0

I am trying to switch the given set of number into every possible cases. For example, the number set is [0,1,2]

The possible numbers which can be built by this set are - 012 - 021 - 102 - 120 - 210 - 201

How am I supposed to write a javascript code to compile a result like this.

Remark : No repeated numbers contain

  • Could you share what you tried so far? – soywod Apr 05 '20 at 17:11
  • Welcome to Stack Overflow! Please visit the [help] to see what and [ask]. HINT: Post effort and CODE. – mplungjan Apr 05 '20 at 17:28
  • (combo = arr => { if (!arr.length) return []; if (arr.length === 1) return [arr]; const results = []; for (let index = arr.length; index--;) { const rest = arr.slice(); rest.splice(index, 1); combo(rest).forEach(combination => { results.push([arr[index]].concat(combination)) }); } return results; })([0, 1, 2]) – termosa Apr 05 '20 at 17:31
  • For example https://stackoverflow.com/a/40655572/295783 – mplungjan Apr 05 '20 at 17:33

0 Answers0