Skip to content

Instantly share code, notes, and snippets.

@Jwing28
Created October 25, 2017 05:29
Show Gist options
  • Save Jwing28/7243bc69462d12e5f9393d373ba439d0 to your computer and use it in GitHub Desktop.
Save Jwing28/7243bc69462d12e5f9393d373ba439d0 to your computer and use it in GitHub Desktop.
permutation
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);
};
@Jwing28
Copy link
Author

Jwing28 commented Oct 25, 2017

This does not work. It is as far as I got.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment