RosettaCodeData/Task/Loop-over-multiple-arrays-simultaneously/JavaScript/loop-over-multiple-arrays-simultaneously-5.js

26 lines
563 B
JavaScript
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
(function () {
'use strict';
// zipListsWith :: ([a] -> b) -> [[a]] -> [[b]]
function zipListsWith(f, xss) {
return (xss.length ? xss[0] : [])
.map(function (_, i) {
return f(xss.map(function (xs) {
return xs[i];
}));
});
}
// concat :: [a] -> s
function concat(lst) {
return ''.concat.apply('', lst);
}
// TEST
return zipListsWith(
concat,
[["a", "b", "c"], ["A", "B", "C"], [1, 2, 3]]
)
.join('\n');
})();