Vanilla JS Flashcards

1
Q

Map (+ example)

A

The map() method creates a new array with the results of calling a provided function on every element in the calling array

const numbers = [2, 4, 8, 10];
const halves = numbers.map(x => x / 2);
// halves is [1, 2, 4, 5]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Filter (+ example)

A

The filter() method creates a new array with all elements that pass the test implemented by the provided function.

const words = [“spray”, “limit”, “elite”, “exuberant”, “destruction”, “present”];

const longWords = words.filter(word => word.length > 6);
// longWords is ["exuberant", "destruction", "present"]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Reduce (+ example)

A

The reduce() method applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.

const total = [0, 1, 2, 3].reduce((sum, value) => sum + value, 1);
// total is 7
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Destructuring Assignment (+ example)

A

Assign the properties of an array or object to variables using syntax that looks similar to array or object literals

var first = someArray[0];
var second = someArray[1];
var third = someArray[2];

var [first, second, third] = someArray;

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

Declarative vs Imperative

A

…..

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