Skip to content

Commit fc350b7

Browse files
Update array.js to add a new function and a change
1. Update the comment describing the unshift method specifying that it returns length of new array. 2. Add ".reverse()" function which I found useful while working with arrays.
1 parent 65b6edd commit fc350b7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/data-structures/arrays/array.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ array.push(4); // array: [2, 5, 1, 9, 6, 7, 4]
1111
// Insert/update values anywhere
1212
array[8] = 3; // array: [2, 5, 1, 9, 6, 7, 4, empty, 3]
1313

14-
// Insert to head, changes every index
14+
// Insert to head, changes every index and returns new length of the array
1515
array.unshift(0); // array: [0, 2, 5, 1, 9, 6, 7, 4, empty, 3];
1616

1717
// Deleting could change all the indexes
@@ -31,3 +31,6 @@ array.splice(2, 1); // delete 1 element at position 2
3131

3232
// Deleting last element from the array
3333
array.pop(); // => array: [2, 5, 1, 9, 6]
34+
35+
//Reversing the array
36+
array.reverse();

0 commit comments

Comments
 (0)