Skip to content

Commit 42fbe4d

Browse files
committed
Added Array Data Structure
1 parent 09fd87a commit 42fbe4d

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/data-structures/Arrays/Array.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,26 @@ class MadeArray{
3535
/**
3636
*
3737
* @param {number} index -index of the element to delete
38-
* @returns
38+
* @returns {any} -element that has been deleted
3939
*/
4040
delete(index){
4141
const element_to_delete = this.elements[index];
4242
this.shiftElements(index);
4343
return element_to_delete;
4444
}
45-
45+
/**
46+
*
47+
* @param {number} index -index of the element that we should start shifting from
48+
*/
4649
shiftElements(index){
50+
//element in the position on index is overwrited and deleted
4751
for(let x = index; x < this.length-1; x++){
4852
this.elements[x] = this.elements[x+1];
4953
}
54+
//delete the last element not to appear two times
5055
delete this.elements[this.length - 1];
56+
5157
this.length--;
5258
}
5359
}
5460

55-
const mine = new MadeArray();
56-
mine.push("1");
57-
mine.push("2");
58-
mine.push("3");
59-
mine.push("4");
60-
61-
console.log(mine);

0 commit comments

Comments
 (0)