-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrooting4you.js
More file actions
45 lines (42 loc) · 1.1 KB
/
rooting4you.js
File metadata and controls
45 lines (42 loc) · 1.1 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
// Code of the lighthouse student needing help
// const judgeVegetable = function (vegetables, metric) {
// let myArray = [];
// console.log("Start", myArray);
// for (let i = 0; i < vegetables.length; i++) {
// myArray.push(vegetables[i][metric]);
// console.log("push", myArray);
// myArray.sort();
// console.log("sort", myArray);
// console.log("compare", vegetables[i][metric], myArray[0]);
// if(vegetables[i][metric] === myArray[0]) { // this quit prematurely
// return vegetables[i].submitter;
// }
// }
// console.log("End", myArray);
// }
// Correcting the student code
const judgeVegetable = function (vegetables, metric) {
const ordered = vegetables.sort(function (a, b) {
return b[metric] - a[metric];
});
return ordered[0][metric];
}
const vegetables = [
{
submitter: 'Sally Tomato-Grower',
redness: 2,
plumpness: 8
},
{
submitter: 'Hamid Hamidson',
redness: 4,
plumpness: 3
},
{
submitter: 'Old Man Franklin',
redness: 10,
plumpness: 5
}
]
console.log("Start run");
console.log(judgeVegetable(vegetables, 'redness'));