# [LeetCode 75] DAY 3 - Kids With the Greatest Number of Candies ## 題目: There are `n` kids with candies. You are given an integer array `candies`, where each `candies[i]` represents the number of candies the `ith` kid has, and an integer `extraCandies`, denoting the number of extra candies that you have. Return a boolean array `result` of length `n`, where `result[i]` is `true` if, after giving the `ith` kid all the `extraCandies`, they will have the **greatest** number of candies among all the kids, or `false` otherwise. Note that **multiple** kids can have the **greatest** number of candies. ## 解題思考 - 先找出原本`candies`最大的數字 - 迭代`candies`加上`extraCandies`是否為最大值 ## 程式碼 ```javascript= function kidsWithCandies(candies, extraCandies) { const max = Math.max(...candies); let results = candies.map(candy => candy + extraCandies >= max); return results; } ``` ## 延伸思考 - `Math.max()`可使用 ES6 的展開運算子 - 若陣列過大,需使用`reduce()`來處理 - `Array.prototype.map()`會回傳一個**新陣列** ## 相關資源 - [1431. Kids With the Greatest Number of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/description/) - [Math.max() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) - [Array.prototype.map() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)