Created
October 25, 2017 05:29
-
-
Save Jwing28/7243bc69462d12e5f9393d373ba439d0 to your computer and use it in GitHub Desktop.
permutation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var permute = function(nums) { | |
nums = nums.join("").split(""); //convert to strings so you can concat values | |
var counter = 0; | |
var rounds = nums.length; | |
var fixed; | |
var result = []; | |
function recurse(nums,counter,rounds) { | |
if(rounds) { | |
rounds--; | |
fixed = nums.splice(counter,1); | |
counter++; | |
result.push(fixed.concat(nums)); //123 | |
nums = nums[1].concat(nums[0]); | |
result.push(fixed.concat(nums));//132 | |
recurse(nums,counter,rounds); | |
} | |
return result; | |
} | |
return recurse(nums,counter,rounds); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This does not work. It is as far as I got.