JavaScript/4kyu/Permutations.js
// The order of the permutations doesn't matter.
The order of the permutations doesn't matter.
The order of the permutations doesn ' t matter .
function permutations(string) {
  if (string.length === 1) return [string];
  let perms = [];
  for (let i=0; i<string.length; i++) {
    let char = string[i];
    let subString = string.slice(0,i) + string.slice(i+1,string.length);
    for (let subPerm of permutations(subString)) {
      perms.push(char + subPerm);       
    }
  }
  return perms.filter((v,idx,self)=>{ return self.indexOf(v) === idx });
}
function permutations ( string ) { if ( string . length === 1 ) return [ string ] ; let perms = [ ] ; for ( let i = 0 ; i < string . length ; i ++ ) { let char = string [ i ] ; let subString = string . slice ( 0 , i ) + string . slice ( i + 1 , string . length ) ; for ( let subPerm of permutations ( subString ) ) { perms . push ( char + subPerm ) ; } } return perms . filter ( ( v , idx , self ) => { return self . indexOf ( v ) === idx } ) ; }
The order of the permutations doesn't matter.
The order of the permutations doesn ' t matter .