-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (57 loc) · 1.25 KB
/
Copy pathindex.js
File metadata and controls
65 lines (57 loc) · 1.25 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
export default class MyArray {
/**
* initialize MyArray
*
* in this case we'll use JavaScript built-in array 😄
* we should probably try using an object next time
*/
constructor() {
this.array = [];
}
/**
* adds an item onto the array
* @param {any} item
*/
add(item) {
this.array.push(item);
}
/**
* removes an item from the array
* @param {any} item
*/
remove(item) {
this.array = this.array.filter(data => data !== item);
}
/**
* look for the given item in the array
* @param {any} item
* @return {number} the array index position of the item found
*/
search(item) {
const foundIndex = this.array.indexOf(item);
return foundIndex || null;
}
/**
* get an item given its index on the array
* @param {number} index index of the item to get
* @return {any} the item found at the given index
*/
getAtIndex(index) {
return this.array[index];
}
/**
* returns the size/length of the array
* @return {number} the size of the array
*/
length() {
return this.array.length;
}
/**
* prints the contents of the array
* @return {any}
*/
print() {
// console.log(this.array.join(' '));
return this.array.join(' ');
}
}