Skip to content

Commit 0796970

Browse files
feat: add topic6 -> left rotation by 1 element
1 parent c69afed commit 0796970

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Topic6/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Left rotation by 1 element
2+
let arr1 = [1, 2, 3, 4, 5];
3+
let copy = arr1[0];
4+
for (let i = 0; i < arr1.length - 1; i++) {
5+
arr1[i] = arr1[i + 1];
6+
}
7+
arr1[arr1.length - 1] = copy;
8+
console.log(arr1);

0 commit comments

Comments
 (0)