repl.it
@jp2kk2/

No repeats

JavaScript

No description

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function permAlone(str) {
  var arr = [];
  //Create permutations arrray
  for(var i in str){
    var curr=[];
    //console.log(i);
    if (arr.length === 0){
      arr.push(str[i]);
      continue;
    } 
    for(var j in arr){
      curr.push(str[i]+arr[j]);
      console.log(arr[j]);
      for(var k=1; k <= arr[j].split("").length;k++){
        var now = arr[j].slice(0).split("");
        now.splice(k,0,str[i]);
        curr.push(now.join(""));
        console.log();
      }
    //console.log(curr);
    }
    arr = curr.slice(0);
  }
  
  //filter permutations with repeated elements
  //console.log(arr);

  arr = arr.filter(function(element){return !/(.)\1+/g.test(element)});
 // console.log(arr);

  return arr.length;
}



permAlone('1234');
Native Browser JavaScript