@jp2kk2/

No repeats

JavaScript

No description

fork
loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.4989879059144533","path":"main.js","file":{"path":"main.js","content":{"asEncoding":{"base64":"ZnVuY3Rpb24gcGVybUFsb25lKHN0cikgewogIHZhciBhcnIgPSBbXTsKICAvL0NyZWF0ZSBwZXJtdXRhdGlvbnMgYXJycmF5CiAgZm9yKHZhciBpIGluIHN0cil7CiAgICB2YXIgY3Vycj1bXTsKICAgIC8vY29uc29sZS5sb2coaSk7CiAgICBpZiAoYXJyLmxlbmd0aCA9PT0gMCl7CiAgICAgIGFyci5wdXNoKHN0cltpXSk7CiAgICAgIGNvbnRpbnVlOwogICAgfSAKICAgIGZvcih2YXIgaiBpbiBhcnIpewogICAgICBjdXJyLnB1c2goc3RyW2ldK2FycltqXSk7CiAgICAgIGNvbnNvbGUubG9nKGFycltqXSk7CiAgICAgIGZvcih2YXIgaz0xOyBrIDw9IGFycltqXS5zcGxpdCgiIikubGVuZ3RoO2srKyl7CiAgICAgICAgdmFyIG5vdyA9IGFycltqXS5zbGljZSgwKS5zcGxpdCgiIik7CiAgICAgICAgbm93LnNwbGljZShrLDAsc3RyW2ldKTsKICAgICAgICBjdXJyLnB1c2gobm93LmpvaW4oIiIpKTsKICAgICAgICBjb25zb2xlLmxvZygpOwogICAgICB9CiAgICAvL2NvbnNvbGUubG9nKGN1cnIpOwogICAgfQogICAgYXJyID0gY3Vyci5zbGljZSgwKTsKICB9CiAgCiAgLy9maWx0ZXIgcGVybXV0YXRpb25zIHdpdGggcmVwZWF0ZWQgZWxlbWVudHMKICAvL2NvbnNvbGUubG9nKGFycik7CgogIGFyciA9IGFyci5maWx0ZXIoZnVuY3Rpb24oZWxlbWVudCl7cmV0dXJuICEvKC4pXDErL2cudGVzdChlbGVtZW50KX0pOwogLy8gY29uc29sZS5sb2coYXJyKTsKCiAgcmV0dXJuIGFyci5sZW5ndGg7Cn0KCgoKcGVybUFsb25lKCcxMjM0Jyk7Cg=="},"asBuffer":null},"loaded":true}}
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