Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,8 @@
|
|||
var a = ["a","b","c"],
|
||||
b = ["A","B","C"],
|
||||
c = [1,2,3],
|
||||
output = "",
|
||||
i;
|
||||
for (i = 0; i < a.length; i += 1) {
|
||||
output += a[i] + b[i] + c[i] + "\n";
|
||||
}
|
||||
|
|
@ -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,25 @@
|
|||
(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');
|
||||
})();
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
aA1
|
||||
bB2
|
||||
cC3
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
(() => {
|
||||
'use strict';
|
||||
|
||||
// GENERIC FUNCTIONS -----------------------------------------------------
|
||||
|
||||
// concat :: [[a]] -> [a]
|
||||
const concat = xs =>
|
||||
xs.length > 0 ? (() => {
|
||||
const unit = typeof xs[0] === 'string' ? '' : [];
|
||||
return unit.concat.apply(unit, xs);
|
||||
})() : [];
|
||||
|
||||
// map :: (a -> b) -> [a] -> [b]
|
||||
const map = (f, xs) => xs.map(f);
|
||||
|
||||
// transpose :: [[a]] -> [[a]]
|
||||
const transpose = xs =>
|
||||
xs[0].map((_, col) => xs.map(row => row[col]));
|
||||
|
||||
// unlines :: [String] -> String
|
||||
const unlines = xs => xs.join('\n');
|
||||
|
||||
// TEST ------------------------------------------------------------------
|
||||
const xs = [
|
||||
['a', 'b', 'c'],
|
||||
['A', 'B', 'C'],
|
||||
[1, 2, 3]
|
||||
];
|
||||
|
||||
return unlines(
|
||||
map(concat, transpose(xs))
|
||||
);
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue