Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -0,0 +1,14 @@
|
|||
var lstOut = ['', '', ''];
|
||||
|
||||
[["a", "b", "c"], ["A", "B", "C"], ["1", "2", "3"]].forEach(
|
||||
function (a) {
|
||||
[0, 1, 2].forEach(
|
||||
function (i) {
|
||||
// side-effect on an array outside the function
|
||||
lstOut[i] += a[i];
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
// lstOut --> ["aA1", "bB2", "cC3"]
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
(function (lstArrays) {
|
||||
|
||||
return lstArrays.reduce(
|
||||
function (a, e) {
|
||||
return [
|
||||
a[0] + e[0],
|
||||
a[1] + e[1],
|
||||
a[2] + e[2]
|
||||
];
|
||||
}, ['', '', ''] // initial copy of the accumulator
|
||||
).join('\n');
|
||||
|
||||
})([
|
||||
["a", "b", "c"],
|
||||
["A", "B", "C"],
|
||||
["1", "2", "3"]
|
||||
]);
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
(function (x, y, z) {
|
||||
|
||||
// function of arity 3 mapped over nth items of each of 3 lists
|
||||
// (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
|
||||
function zipWith3(f, xs, ys, zs) {
|
||||
return zs.length ? [f(xs[0], ys[0], zs[0])].concat(
|
||||
zipWith3(f, xs.slice(1), ys.slice(1), zs.slice(1))) : [];
|
||||
}
|
||||
|
||||
function concat(x, y, z) {
|
||||
return ''.concat(x, y, z);
|
||||
}
|
||||
|
||||
return zipWith3(concat, x, y, z).join('\n')
|
||||
|
||||
})(["a", "b", "c"], ["A", "B", "C"], [1, 2, 3]);
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
(function (lists) {
|
||||
|
||||
// [[a]] -> [[a]]
|
||||
function zip(lists) {
|
||||
var lng = lists.length,
|
||||
lstHead = lng ? [].concat.apply([], lists.map(function (lst) {
|
||||
return lst.length ? [lst[0]] : [];
|
||||
})) : [];
|
||||
|
||||
return lstHead.length === lng ? [lstHead].concat(
|
||||
zip(lists.map(function (x) {
|
||||
return x.slice(1);
|
||||
}))
|
||||
) : [];
|
||||
}
|
||||
|
||||
// [a] -> s
|
||||
function concat(lst) {
|
||||
return ''.concat.apply('', lst);
|
||||
}
|
||||
|
||||
return zip(lists).map(concat).join('\n')
|
||||
|
||||
})([["a", "b", "c"], ["A", "B", "C"], [1, 2, 3]]);
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
aA1
|
||||
bB2
|
||||
cC3
|
||||
Loading…
Add table
Add a link
Reference in a new issue