arrays Flashcards

1
Q

includes

A

let b=[10, 20, 30, 40]

b.includes(10)

=> true

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

map

A

b.map(one=>one+10)

=> [20, 30, 40, 50]

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

reduce

A

plus

let b=[10, 20, 30, 40]
b.reduce((one,two)=>one+two,0)
=> 100

let b = [10, 20, 30, 40]
b.reduce((one, two) => one * two, 1)
=> 2400

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

reduce #order

A

let a = [100, 200, 400, 100, 200];

let b = a.reduce((one, two) => {
if (one[two]) {
one[two] = one[two] + 1;
} else {
one[two] = 1;
}

return one;
}, {});

console.log(b);

=> { ‘100’: 2, ‘200’: 2, ‘400’: 1 }

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

remove duplicates

A

const one = [2, 1, 3, 5, 3, 2];
let two = […new Set(one)]

two # [ 2, 1, 3, 5 ]

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

sort #ordenar

A

descendente

const one = [2, 1, 3, 5, 3, 2];

const two = one.sort() THE SAME const two = one.sort((a-b)=>a-b)

const two = one.sort() THE SAME const two = one.sort((a-b)=>a-b)

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

array.findIndex(CALLBACK) // array.find(CALLBACK)
=> 3

array.indexof(2)
=>3

A

they are the same
both return only a value

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

const a = [2, 1, 3, 5, 3, 2];

const b = a.forEach((one, two, three) => {
console.log(one, “=”, two, “=”, three);
});

A

2 = 0 = [ 2, 1, 3, 5, 3, 2 ]
1 = 1 = [ 2, 1, 3, 5, 3, 2 ]
3 = 2 = [ 2, 1, 3, 5, 3, 2 ]
5 = 3 = [ 2, 1, 3, 5, 3, 2 ]
3 = 4 = [ 2, 1, 3, 5, 3, 2 ]
2 = 5 = [ 2, 1, 3, 5, 3, 2 ]

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

convert // text => array // split

const a=”sadkljsaldkñjf”

const b= a.split(“”)
console.log(b);

A

[
‘s’, ‘a’, ‘d’, ‘k’,
‘l’, ‘j’, ‘s’, ‘a’,
‘l’, ‘d’, ‘k’, ‘ñ’,
‘j’, ‘f’
]

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

split // second example

const a=”sadkljsaldkñjf”

A

=> a
[“sadkljsaldkñjf”]

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

condición ? expresión1 : expresión2

A

const cnt = original.length > modified.length ? original : modified;

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

reverse // split

A

const a =[100,200,300]

const b=a.reverse()

=> [ 300, 200, 100 ]

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

join

A

example1

const a = [“one”,”two”,”three”]
const b = a.join(“-“);
=> one-two-three // string

const a = [“one”,”two”,”three”]
const b = a.join();
=> one,two,three // string

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

match // string.match(regex)

A

let text = “El gato se sube al árbol.”;

let result = text.match(/gato/);
console.log(result); // Output: [“gato”]

result = text.match(/perro/);
console.log(result); // Output: null

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