-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharraypt2.js
More file actions
86 lines (73 loc) · 1.83 KB
/
arraypt2.js
File metadata and controls
86 lines (73 loc) · 1.83 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
////////// TASK 1 //////////
/**
* isArrayLengthOdd(numbers):
* - receives array `numbers`
* - returns true if array has an odd length
let num = isOdd(12);
console.log(num);number of elements
* - returns false otherwise
*
* e.g.
* isArrayLengthOdd([1, 2, 3]) -> true
* isArrayLengthOdd([1, 2, 3, 4]) -> flase
*/
function isArrayLengthOdd(numbers) {
// Your code here
if (numbers.length % 2 == 0) {
return false;
} else {
return true;
}
}
console.log(isArrayLengthOdd([1, 2, 3]));
////////// TASK 2 //////////
/**
* isArrayLengthEven(numbers):
* - receives array `numbers`
* - returns true if array has an even number of elements
* - returns false otherwise
*
* e.g.
* isArrayLengthEven([1, 2, 3]) -> false
* isArrayLengthEven([1, 2, 3, 4]) -> true
*/
function isArrayLengthEven(numbers) {
// Your code here
if (numbers.length % 2 != 0) {
return false;
} else {
return true;
}
}
console.log(isArrayLengthEven([1, 2, 3]));
////////// TASK 3 //////////
/**
* addLailaToArray(instructors):
* - receives array `instructors`
* - returns a new array that's a copy of array `instructors` with additional string "Laila"
*
* e.g.
* addLailaToArray(["Mshary", "Hasan"]) -> ["Mshary", "Hasan", "Laila"]
*/
function addLailaToArray(instructors) {
// Your code here
let addLailaToArray = ["Mshary", "Hasan"];
addLailaToArray.push(instructors);
console.log(addLailaToArray);
}
addLailaToArray("Laila");
////////// TASK 4 //////////
/**
* eliminateTeam(teams):
* - receives array `teams`
* - removes the last element from the array and return it
*
* e.g.
* eliminateTeam(["Brazil", "Germany", "Italy"]) -> "Italy"
*/
function eliminateTeam(teams) {
// Your code here
// let x = ["Brazil", "Germany", "Italy"];
return console.log(teams.pop());
}
eliminateTeam(["Brazil", "Germany", "Italy"]);