suchen

Heim  >  Fragen und Antworten  >  Hauptteil

js gibt alle Kombinationen an

Wie bekomme ich die Kombination?
Verwendung von js
Haben Sie gute Ideen und Ratschläge~

过去多啦不再A梦过去多啦不再A梦2753 Tage vor420

Antworte allen(4)Ich werde antworten

  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:17:45

    考来的。。。

    function permute(input) {
      var permArr = [],
      usedChars = [];
      function main(input){
        var i, ch;
        for (i = 0; i < input.length; i++) {
          ch = input.splice(i, 1)[0];
          usedChars.push(ch);
          if (input.length == 0) {
            permArr.push(usedChars.slice());
          }
          main(input);
          input.splice(i, 0, ch);
          usedChars.pop();
        }
        return permArr;
      }
      return main(input).join('\n');
    };
    console.log(permute(['foo','bar','hello','world']));

    Antwort
    0
  • 怪我咯

    怪我咯2017-05-19 10:17:45

    var arr = ['foo', 'bar', 'hello', 'world']; 
    
    // 4 3 2 1 
    var first = {}
    var result = []; 
    arr.forEach((first, idx, its) => {
        its.filter(e => e!==first).forEach((sec, idx, its) => {
            its.filter(e => e!==sec).forEach((third, idx, its)=> { 
                its.filter(e => e!=third).forEach((forth, idx, its) => {
                    console.log(first, sec, third, forth); 
                    result.push(first + sec + third + forth); 
                }); 
            });
        });
    });

    = = 丧心病狂的遍历。。。

    Antwort
    0
  • 習慣沉默

    習慣沉默2017-05-19 10:17:45

    可以用有向图方法,得出四个节点所有路径

    Antwort
    0
  • PHP中文网

    PHP中文网2017-05-19 10:17:45

    栈和队列

    Antwort
    0
  • StornierenAntwort