scrimba
Javascript Hacks with ES6-ES7
Javascript Hacks with ES6-ES7 #32
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Javascript Hacks with ES6-ES7 #32
AboutCommentsNotes
Javascript Hacks with ES6-ES7 #32
Expand for more info
index.js
run
preview
console
// single  liner codes
const all = (arr, fn=Boolean) => arr.every(fn);

all([1,2,3,4,5], x => x > 0);

// how can we check all arrary elm are equal

const allEqual = arr => arr.every(val => val === arr[0])

allEqual([1,1,1,1,1,]);
allEqual([1,2,3,4]);



const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0);

countOccurrences([1, 1, 2, 1, 2, 3], 1); // 3
Console
"Hello from JavaScript"
,
index.html
-2:32