JS syntax / functions Flashcards

1
Q

Array reduce

A
const array1 = [1, 2, 3, 4];
const reducer = (accumulator, currentValue) => accumulator + currentValue;
// 1 + 2 + 3 + 4
console.log(array1.reduce(reducer));
// expected output: 10
// 5 + 1 + 2 + 3 + 4
console.log(array1.reduce(reducer, 5));
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to make a subarray

A

const animals = [‘ant’, ‘bison’, ‘camel’, ‘duck’, ‘elephant’];

console.log(animals.slice(2));
// expected output: Array ["camel", "duck", "elephant"]
console.log(animals.slice(2, 4));
// expected output: Array ["camel", "duck"]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Math.random range

A

[0,1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly