Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update array-left-rotation.js #1

Merged
merged 1 commit into from Jan 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions array-left-rotation.js
Expand Up @@ -62,7 +62,7 @@ function getResultsUsingLoop() {
//Solution using array.map()
function getResultUsingArrayMap() {
let result = data.map(function(value, index) {
let pos = index + d;
let pos = parseInt(index) + parseInt(d);
if (pos > n-1) {
pos = pos - n;
}
Expand All @@ -74,10 +74,10 @@ function getResultUsingArrayMap() {

//Solution using array.shift()
function getResultsUsingArrayShift() {
let temp = datas.slice(0);
let temp = data.slice(0);
for (let i=0; i<n-1; i++) {
let first = temp.shift();
temp.push(first);
}
return temp;
}
}