Array.Filter Flashcards

1
Q

let results = arr.filter(function(____ , ______ , ________) {

});

A

element, index, array

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

var words = [‘spray’, ‘limit’, ‘elite’, ‘exuberant’, ‘destruction’, ‘present’];

const result = words.filter(word => word.length > 6);

console.log(result);
// expected output:
A

Array [“exuberant”, “destruction”, “present”]

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

Using the filter method on the years array, return an array of only the years in the twentieth century (remember: the twentieth century includes the year “2000”).

const years = [1989, 2015, 2000, 1999, 2013, 1973, 2012];
let century20;
A

century20 = years.filter( year => year >= 2000 );

console.log(century20);

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

what 3 elements of .Filter() are optional?

A

indexOptional
arrayOptional
thisArgOptional

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
function isBigEnough(value) {
  return value >= 10;
}
var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);
// filtered is
A

[12, 130, 44]

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

function isBigEnough // code

var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);
// filtered is [12, 130, 44]
A

(value) {
return value >= 10;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
var arr = [1,2,true,4,{"abc":123},6,7,{"def":456},9,[10]]
var res = \_\_\_\_\_\_\_\_\_\_ // [1, 2, true, 4, 6, 7, 9, Array[1]]
A

arr.filter(Number);

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

console.log(1 == true);

A

true

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

console.log(1 === true);

A

false

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

var words = [‘spray’, ‘limit’, ‘elite’, ‘exuberant’, ‘destruction’, ‘present’];

const result = words.filter// return a word greater than 6 characters

console.log(result);
// expected output: Array ["exuberant", "destruction", "present"]
A

(word => word.length > 6);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
const userNames =['Steve', 'mike', 'Same'];
const user = userNames

//filter names with S

A

(name=> name.charAt(0) === “s”)

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