Skip to content

Commit d18d818

Browse files
committed
rotational array
1 parent 349517f commit d18d818

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// 44. Left Rotate by One in an Array
2+
3+
{
4+
function rotationFunction(arr) {
5+
if (arr.length <= 1) {
6+
return arr;
7+
}
8+
9+
return arr.map((_, index, array) => array[(index + 1) % array.length]);
10+
}
11+
12+
let arr1 = [1, 2, 3, 4, 5];
13+
let result = rotationFunction(arr1);
14+
15+
16+
console.log("Original Array:", arr1);
17+
console.log("Array after rotation", result);
18+
}

0 commit comments

Comments
 (0)