forked from LEARNAcademy/JS-foundations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
array-methods-practice.js
46 lines (34 loc) · 1.68 KB
/
array-methods-practice.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Array Methods Practice
// Below are exercises in using array methods. Beneath each prompt write the code to fulfill the exercise requirement.
// Exercise 1
// Consider this variable:
var groceryList1 = ["apples", "carrots", "oatmeal"]
// Write the code that will add "granola" to the end of array without altering the original array.
// Exercise 2
// Consider this variable:
var groceryList2 = ["chips", "dip", "cookies"]
// Write the code that will add "soda" to the end of the original array.
// Exercise 3
// Consider this variable:
var numbers1 = [1, 2, 3, 4, 5]
// Write the code that will add the number 0 to the beginning of the array without altering the original array.
// Exercise 4
// Consider this variable:
var numbers2 = [2, 4, 6, 8, 10]
// Write the code that will add the number 0 to the beginning of the original array.
// Exercise 5
// Consider this variable:
var numbers3 = [2, 13, 6, 8, 4, 2]
// Write the code that finds the index of the first appearance of the number 2.
// Exercise 6
// Write the code that finds the index of the last appearance of the number 2.
// Exercise 7
// Consider this variable:
var chars = ["y", "a", "r", "r", "a"]
// Write the code that brings all the letters in the chars array together into a string.
// Exercise 8
// Write the code that reverses the order of the letters in the chars array and saves it into a variable called charsReversed.
// Exercise 9
// Write the code that brings all the letters in the charsReversed array together into a string with a hyphen between each letter.
// Exercise 10
// Write the code that brings all the letters in the charsReversed Array together into a string without separators.