-
Notifications
You must be signed in to change notification settings - Fork 0
/
03_pushUnshiftArrayItems.js
31 lines (25 loc) · 1.03 KB
/
03_pushUnshiftArrayItems.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* Add Items to an Array with push() and unshift() */
/* The push and unshift methods take one or more items
and add them to an array, either at the end or the
beginning respectively. */
let twentyThree = "XXIII";
let romanNumerals = ['XXI', 'XXII'];
romanNumerals.unshift('XIX', 'XX');
console.log(romanNumerals); // ['XIX', 'XX', 'XXI', 'XXII']
romanNumerals.push(twentyThree);
console.log(romanNumerals); // ['XIX', 'XX', 'XXI', 'XXII', 'XXIII']
/* We have defined a function, mixedNumbers, which we are
passing an array as an argument. Modify the function by
using push() and unshift() to add 'I', 2, 'three'
to the beginning of the array and 7, 'VIII', 9 to the end
so that the returned array contains representations of the
numbers 1 - 9 in order. */
function mixedNumbers(arr) {
// Only change code below this line
arr.unshift('I', 2, 'three');
arr.push(7, 'VIII', 9);
// Only change code above this line
return arr;
}
console.log(mixedNumbers(['IV', 5, 'six']));
// ['I', 2, 'three', 'IV', 5, 'six', 7, 'VIII', 9]