Array.Map Flashcards

1
Q

var array1 = [1, 4, 9, 16];

const test = array1______(x => x * 2);

console.log(test);
// expected output: Array [2, 8, 18, 32]
A

.map

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

var array1 = [1, 4, 9, 16];

// pass a function to map
const map1 = \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
console.log(map1);
// expected output: Array [2, 8, 18, 32]
A

array1.map(x => x * 2);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
var array1 = [1, 4, 9, 16];
const map1 = array1.\_\_\_\_\_\_\_(x => x * 2);

// expected output: Array [2, 8, 18, 32]

A

Map

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
var array1 = [1, 4, 9, 16];
const map1 = array1.map(x => x * 2);

console.log(map1==array1);

A

false

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

The ________method creates a new array with the results of calling a provided function on every element in the calling array.

A

map()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
var nums = [
    5,
    9,
    7
];
//WRITE .MAP THAT ADDS 1 TO EACH NUMBER
var oneBetterThanNums =
A
var oneBetterThanNums = nums.map(function (num) {
    return num + 1;
});
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Use the map method on the daysOfWeek array, creating a new array of abbreviated week days. Each abbreviated string should be the first three letters of the long version in daysOfWeek. Store the new array in the variable abbreviatedDays.

const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
let abbreviatedDays;
A

let abbreviatedDays = daysOfWeek.map(day => day.slice(0,3))

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

_________— executes a provided function once for each array element.
__________— creates a new array with the results of calling a provided function on every element in the calling array.

A

forEach() 

map() 

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

When we need to iterate and return the data for each element – we can use ________.

A

map

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
const authors = [
  { firstName: "Beatrix", lastName: "Potter" },
  { firstName: "Ann", lastName: "Martin" },
  { firstName: "Beverly", lastName: "Cleary" },
  { firstName: "Roald", lastName: "Dahl" },
  { firstName: "Lewis", lastName: "Carroll" }
];
let fullAuthorNames;
// fullAuthorNames should be: ["Beatrix Potter", "Ann Martin", "Beverly Cleary", "Roald Dahl", "Lewis Carroll"]
// Write your code below
A

authors. map((authors)=> ${authors.lastName} + ${authors.firstName});
console. log(fullAuthorNames);

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

//FIX THIS CODE

const authors = [
  { firstName: "Beatrix"},
  { firstName: "Ann",},
];

const user = userNAmes.map(name=> {name : name})

A

(name=> ({name : name}))

add pertness to object literal
only with arrow functions

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