-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbiggerPrice.js
More file actions
36 lines (31 loc) · 950 Bytes
/
biggerPrice.js
File metadata and controls
36 lines (31 loc) · 950 Bytes
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
// перебираем объект
function biggerPrice(limit, data)
{
let res = [];
data.sort((prev,next) => next.price - prev.price);
for (let i = 0; i < limit; i++) {
res.push(data[i]);
}
return res;
}
console.log('Example:')
console.log(biggerPrice(2, [
{"name": "bread", "price": 100},
{"name": "wine", "price": 138},
{"name": "meat", "price": 15},
{"name": "water", "price": 1}
]))
assert.deepEqual(biggerPrice(2, [
{"name": "bread", "price": 100},
{"name": "wine", "price": 138},
{"name": "meat", "price": 15},
{"name": "water", "price": 1}
]), [
{"name": "wine", "price": 138},
{"name": "bread", "price": 100}
])
assert.deepEqual(biggerPrice(1, [
{"name": "pen", "price": 5},
{"name": "whiteboard", "price": 170}
]), [{"name": "whiteboard", "price": 170}])
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");