-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
Copy patharrays.js
43 lines (34 loc) · 926 Bytes
/
arrays.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
var chocolateBars = ["snickers", "hundred grand", "kitkat", "skittles"]
function addElementToBeginningOfArray(array, element) {
return [element, ...array];
}
function destructivelyAddElementToBeginningOfArray(array, element) {
array.unshift(element)
return array
}
function addElementToEndOfArray(array, element) {
return [...array, element];
}
function destructivelyAddElementToEndOfArray(array, element) {
array.push(element)
return array
}
function accessElementInArray(array, index) {
return array[index]
}
function destructivelyRemoveElementFromBeginningOfArray(array) {
array.shift(array)
return array
}
function removeElementFromBeginningOfArray(array) {
array = array.slice(1)
return array
}
function destructivelyRemoveElementFromEndOfArray(array) {
array.pop(array)
return array
}
function removeElementFromEndOfArray(array) {
array = array.slice(0, array.length - 1)
return array
}