Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 70b63ec

Browse files
fix: handle cases where k is larger than array length
1 parent 7997cc3 commit 70b63ec

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

‎Topic6/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ console.log(arr2);
2525
// Left rotation by k elements
2626
let arr3 = [1, 2, 3, 4, 5];
2727
let k = Number(prompt("Enter k value"));
28+
k = k % arr3.length;
2829

2930
for (let j = 0; j < k; j++) {
3031
let copy3 = arr3[0];

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /