Skip to content

Instantly share code, notes, and snippets.

@rayyee
Created April 8, 2021 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayyee/72f4f2e3bc48453ed46a8783d8217295 to your computer and use it in GitHub Desktop.
Save rayyee/72f4f2e3bc48453ed46a8783d8217295 to your computer and use it in GitHub Desktop.
import R from "ramda";
const scaner = y => R.map(x => R.join(";", [y, x]));
const permutationOrderly = aoa => R.reduce(
(a, b) => R.flatten( R.juxt( R.map( scaner, a ) )( b ) ),
R.head(aoa),
R.remove(0, 1, aoa)
);
// -- trace
const data = [
["a", "b", "c", "d"],
[1, 2, 3, 4, 5, 6, 7],
["A", "B", "C"],
["一", "二"]
];
const results = permutationOrderly(data);
console.log("input ", data);
console.log("output ", results);
console.log("check ",
R.equals(R.uniq(results).length, results.length),
R.all(R.identity, R.map(x => R.eqBy(x, data.length), results))
);
@rayyee
Copy link
Author

rayyee commented Apr 8, 2021

output [
'a;1;A;一', 'a;1;A;二', 'a;1;B;一', 'a;1;B;二', 'a;1;C;一', 'a;1;C;二',
'a;2;A;一', 'a;2;A;二', 'a;2;B;一', 'a;2;B;二', 'a;2;C;一', 'a;2;C;二',
'a;3;A;一', 'a;3;A;二', 'a;3;B;一', 'a;3;B;二', 'a;3;C;一', 'a;3;C;二',
'a;4;A;一', 'a;4;A;二', 'a;4;B;一', 'a;4;B;二', 'a;4;C;一', 'a;4;C;二',
'a;5;A;一', 'a;5;A;二', 'a;5;B;一', 'a;5;B;二', 'a;5;C;一', 'a;5;C;二',
'a;6;A;一', 'a;6;A;二', 'a;6;B;一', 'a;6;B;二', 'a;6;C;一', 'a;6;C;二',
'a;7;A;一', 'a;7;A;二', 'a;7;B;一', 'a;7;B;二', 'a;7;C;一', 'a;7;C;二',
'b;1;A;一', 'b;1;A;二', 'b;1;B;一', 'b;1;B;二', 'b;1;C;一', 'b;1;C;二',
'b;2;A;一', 'b;2;A;二', 'b;2;B;一', 'b;2;B;二', 'b;2;C;一', 'b;2;C;二',
'b;3;A;一', 'b;3;A;二', 'b;3;B;一', 'b;3;B;二', 'b;3;C;一', 'b;3;C;二',
'b;4;A;一', 'b;4;A;二', 'b;4;B;一', 'b;4;B;二', 'b;4;C;一', 'b;4;C;二',
'b;5;A;一', 'b;5;A;二', 'b;5;B;一', 'b;5;B;二', 'b;5;C;一', 'b;5;C;二',
'b;6;A;一', 'b;6;A;二', 'b;6;B;一', 'b;6;B;二', 'b;6;C;一', 'b;6;C;二',
'b;7;A;一', 'b;7;A;二', 'b;7;B;一', 'b;7;B;二', 'b;7;C;一', 'b;7;C;二',
'c;1;A;一', 'c;1;A;二', 'c;1;B;一', 'c;1;B;二', 'c;1;C;一', 'c;1;C;二',
'c;2;A;一', 'c;2;A;二', 'c;2;B;一', 'c;2;B;二', 'c;2;C;一', 'c;2;C;二',
'c;3;A;一', 'c;3;A;二', 'c;3;B;一', 'c;3;B;二',
... 68 more items
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment