What do you want to save?
Add Code snippet
New code examples
-
Javascript 2022-03-17 10:00:12
Math max with array js
// For large data, it's better to use reduce. Supose arr has a large data in this case: const arr = [1, 5, 3, 5, 2]; const max = arr.reduce((a, b) => { return Math.max(a, b) }); // For arrays with relatively few elements you can use apply: const max ... Add solution -
Javascript 2022-03-02 09:45:07
javascript Count the occurrences of a value in an array
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0); // Examples countOccurrences([2, 1, 3, 3, 2, 3], 2); // 2 countOccurrences(['a', 'b', 'a', 'c', 'a', 'b'], 'a'); // 3 Add solution -
Javascript 2022-02-28 13:20:48
how to count occurences in an array with javascript
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0); // Examples countOccurrences([2, 1, 3, 3, 2, 3], 2); // 2 countOccurrences(['a', 'b', 'a', 'c', 'a', 'b'], 'a'); // 3 Add solution -
Javascript 2022-02-26 18:35:07
js max array
// For large data, it's better to use reduce. Supose arr has a large data in this case: const arr = [1, 5, 3, 5, 2]; const max = arr.reduce((a, b) => { return Math.max(a, b) }); // For arrays with relatively few elements you can use apply: const max ... Add solution -
Javascript 2022-02-24 15:50:02
maximum element in an array javascript
// For large data, it's better to use reduce. Supose arr has a large data in this case: const arr = [1, 5, 3, 5, 2]; const max = arr.reduce((a, b) => { return Math.max(a, b) }); // For arrays with relatively few elements you can use apply: const max ... Add solution -
Javascript 2022-02-13 08:40:02
your company assigns each customer a membership id
//your company assigns each customer a membership id function createCheckDigit(membershipId) { let arr = membershipId.split(''); while (arr.length > 1) { arr = arr.reduce((count, item) => { return count + parseInt(item); },0); ... Add solution -
Javascript 2022-01-28 05:22:09
Uncaught SyntaxError: await is only valid in async function
//If you are using reduce(), the since the result of the first accumulation loop //will be used in the second second loop.so need one more asyc in front of // reduce parameters: const sleep = (n) => new Promise((res) => setTimeout(res, n)); const... Add solution
Best helpers
Ranking is empty