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

2016-12-05 22:15:40 +01: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];
}));
});
2015-11-18 06:14:39 +00:00
}
2016-12-05 22:15:40 +01:00
// concat :: [a] -> s
2015-11-18 06:14:39 +00:00
function concat(lst) {
return ''.concat.apply('', lst);
}
2018-06-22 20:57:24 +00:00
// TEST
2016-12-05 22:15:40 +01:00
return zipListsWith(
concat,
[["a", "b", "c"], ["A", "B", "C"], [1, 2, 3]]
)
.join('\n');
})();