I’m given an array of entries in javascript, such as :
var entries = ["cat", "dog", "chicken", "pig"];
I’d now like to iterate over all unique pairwise combinations of them. In this example, I’d like to see:
("cat", "dog"),
("cat", "chicken"),
...
In other languages, like scala, this is super easy. You just do
entries.combinations(2)
is there a similar method or function in a library for javascript? Or do I just have to write it myself the ugly way with nested loops?
Not as far as I know. I think you have to stick to nested loops.
A similar question has been asked here: Output each combination of an array of numbers with javascript maybe you can find an answer there.