File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed
src/data-structures/Arrays Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -35,27 +35,26 @@ class MadeArray{
35
35
/**
36
36
*
37
37
* @param {number } index -index of the element to delete
38
- * @returns
38
+ * @returns { any } -element that has been deleted
39
39
*/
40
40
delete ( index ) {
41
41
const element_to_delete = this . elements [ index ] ;
42
42
this . shiftElements ( index ) ;
43
43
return element_to_delete ;
44
44
}
45
-
45
+ /**
46
+ *
47
+ * @param {number } index -index of the element that we should start shifting from
48
+ */
46
49
shiftElements ( index ) {
50
+ //element in the position on index is overwrited and deleted
47
51
for ( let x = index ; x < this . length - 1 ; x ++ ) {
48
52
this . elements [ x ] = this . elements [ x + 1 ] ;
49
53
}
54
+ //delete the last element not to appear two times
50
55
delete this . elements [ this . length - 1 ] ;
56
+
51
57
this . length -- ;
52
58
}
53
59
}
54
60
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 ) ;
You can’t perform that action at this time.
0 commit comments