-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmax_by.yml
More file actions
50 lines (50 loc) · 1.37 KB
/
max_by.yml
File metadata and controls
50 lines (50 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
name: max_by
topic: math
args:
required:
- name: elements
type: array
- name: expr
type: [expression->number, expression->string]
returns:
type: any
desc: |
Return the maximum element in an array using the expression `expr` as the
comparison key. The entire maximum element is returned.
Below are several examples using the `people` array (defined above) as the
given input.
examples:
test5:
context: &data
people:
- {age: 20, age_str: '20', bool: true, name: a, extra: foo}
- {age: 40, age_str: '40', bool: false, name: b, extra: bar}
- {age: 30, age_str: '30', bool: true, name: c}
- {age: 50, age_str: '50', bool: false, name: d}
- {age: 10, age_str: '10', bool: true, name: 3}
args: [people, '&age']
returns: {age: 50, age_str: '50', bool: false, name: d}
test6:
context: *data
args: [people, '&age_str']
returns: {age: 50, age_str: '50', bool: false, name: d}
test7:
context: *data
args: [people, '&bool']
error: invalid-type
test8:
context: *data
args: [people, '&extra']
error: invalid-type
test9:
context: *data
args: [people, '&to_number(age_str)']
returns: {age: 50, age_str: '50', bool: false, name: d}
test3:
context: *data
args: [people, '&age_str']
error: invalid-type
test4:
context: *data
args: [people, age]
error: invalid-type