Array Arrangement Permutation

前端 未结 4 566
半阙折子戏
半阙折子戏 2021-01-26 18:09

Looking for a way to sequentially find different arrangement possibilities of an array. I only care about adding them sequentially, doesn\'t need skip or shuffle values.

4条回答
  •  终归单人心
    2021-01-26 18:26

    var array = ['a', 'b', 'c', 'd', 'e', 'f'];
    results = [];
    for (x = 1; x < array.length + 1; ++x) {
      results.push(array.slice(0, x).toString().replace(/,/g, ""))
    }
    //PRINT ALL RESULTS IN THE RESULTS VARIABLE
    for (x = 0; x < results.length; ++x) {
      console.log(results[x])
    }

提交回复
热议问题