Skip to content

Commit f7e91ec

Browse files
committed
feat: add array rotation algorithms
1 parent 1d07bc7 commit f7e91ec

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Data-Structures/Array/RotateArray.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @returns {number[]} - New array rotated to the right by k positions
77
* @throws {TypeError} - If input is not an array
88
*/
9-
export function rotateRight(array, k) {
9+
const rotateRight = (array, k) => {
1010
if (!Array.isArray(array)) {
1111
throw new TypeError('Input must be an array')
1212
}
@@ -36,7 +36,7 @@ export function rotateRight(array, k) {
3636
* @returns {number[]} - New array rotated to the left by k positions
3737
* @throws {TypeError} - If input is not an array
3838
*/
39-
export function rotateLeft(array, k) {
39+
const rotateLeft = (array, k) => {
4040
if (!Array.isArray(array)) {
4141
throw new TypeError('Input must be an array')
4242
}
@@ -57,3 +57,5 @@ export function rotateLeft(array, k) {
5757

5858
return rotated
5959
}
60+
61+
export { rotateRight, rotateLeft }

0 commit comments

Comments
 (0)