Skip to content

Commit 59b9d59

Browse files
author
baochau.dinh
committed
js-concepts: leetcode prob.189 - rotate array
1 parent 7b2529e commit 59b9d59

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

LeetCode/189. Rotate Array/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var rotate = function(nums, k) {
2+
let value = k % nums.length;
3+
let splicePart = nums.splice(0, nums.length - value);
4+
splicePart.map(item => nums.push(item));
5+
return nums;
6+
};
7+
8+
console.log(rotate([1, 2, 3, 4, 5, 6, 7], 3));

0 commit comments

Comments
 (0)