Kids With the Greatest Number of Candies LeetCode solution in JavaScript

1
var kidsWithCandies = function (candies, extraCandies) {
2
//First find out maximum number in array:->
3
let max = 0,
4
res = [];
5
for (let i = 0; i < candies.length; i++) {
6
if (candies[i] > max) max = candies[i];
7
}
8
console.log(max);
9

10
/*Now add extraCandies with every element in array and checks if
11
that sum is equals to or greater than max and return true and false otherwise; */
12

13
for (let i = 0; i < candies.length; i++) {
14
let temp = candies[i] + extraCandies;
15
if (temp >= max) res.push(true);
16
else res.push(false);
17
}
18
return res;
19
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0