forked from AustinCodingAcademy/javascript-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercises.js
More file actions
60 lines (47 loc) · 1.65 KB
/
exercises.js
File metadata and controls
60 lines (47 loc) · 1.65 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// 1. Length
let cars = ["Ford", "Chevrolet", "Dodge", "Jeep"];
console.log("cars.length: ", cars.length, "\n");
// 2. Concat
let moreCars = ["Nissan", "Fiat", "Lexus", "Honda"];
let totalCars = cars.concat(moreCars);
console.log("cars concat: ", totalCars, "\n");
// 3. indexOf and lastIndexOf
console.log("indexof Honda: ", moreCars.indexOf("Honda"), "\n");
console.log("indexof Ford: ", cars.lastIndexOf("Ford"), "\n");
// 4. join
let stringOfCars = totalCars.join(" ");
console.log("stringofcars join: ", stringOfCars, "\n");
// 5. split
console.log("stringofcars split: ", stringOfCars.split(" "), "\n");
// 6. reverse
let carsInReverse = totalCars.reverse();
console.log("carsinreverse reverse: ", carsInReverse, "\n");
// 7. sort
let sortedCars = []
sortedCars = sortedCars.concat(carsInReverse)
sortedCars.sort();
console.log("sortedcars concat: ", sortedCars, "\n");
// 8. slice
let removedCars = carsInReverse.slice(3, 5);
console.log("removedcars slice: ", removedCars, " ", carsInReverse, "\n");
// 9. splice
let spliced = carsInReverse.splice(1, 2, "Ford", "Honda",);
console.log("carsinreverse splice: ", carsInReverse, "\n");
// 10. push
carsInReverse.push("Lexus", "Fiat");
console.log("carsinreverse push: ", carsInReverse, "\n");
// 11. pop
carsInReverse.pop([-1]);
console.log("carsinreverse pop: ", carsInReverse, "\n");
//12. shift
carsInReverse.shift([1]);
console.log("carsinreverse shift: ", carsInReverse, "\n");
//13. unshift
carsInReverse.unshift("Ferrari");
console.log("carsinreverse unshift: ", carsInReverse, "\n");
//1. forEach
let numbers = [ 23, 45, 0, 2 ];
numbers.forEach(function(numbers) {
numbers += 2;
console.log(numbers);
});