Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,4 @@
var val = 0;
do {
print(++val);
} while (val % 6);

View file

@ -0,0 +1,19 @@
function doWhile(varValue, fnBody, fnTest) {
'use strict';
var d = fnBody(varValue); // a transformed value
return fnTest(d) ? [d].concat(
doWhile(d, fnBody, fnTest)
) : [d];
}
console.log(
doWhile(0, // initial value
function (x) { // Do body, returning transformed value
return x + 1;
},
function (x) { // While condition
return x % 6;
}
).join('\n')
);

View file

@ -0,0 +1,6 @@
1
2
3
4
5
6

View file

@ -0,0 +1,28 @@
function range(m, n) {
'use strict';
return Array.apply(null, Array(n - m + 1)).map(
function (x, i) {
return m + i;
}
);
}
function takeWhile(lst, fnTest) {
'use strict';
var varHead = lst.length ? lst[0] : null;
return varHead ? (
fnTest(varHead) ? [varHead].concat(
takeWhile(lst.slice(1), fnTest)
) : []
) : []
}
console.log(
takeWhile(
range(1, 100),
function (x) {
return x % 6;
}
).join('\n')
);

View file

@ -0,0 +1,5 @@
1
2
3
4
5

View file

@ -0,0 +1,46 @@
(() => {
'use strict';
// unfoldr :: (b -> Maybe (a, b)) -> b -> [a]
function unfoldr(mf, v) {
for (var lst = [], a = v, m;
(m = mf(a)) && m.valid;) {
lst.push(m.value), a = m.new;
}
return lst;
}
// until :: (a -> Bool) -> (a -> a) -> a -> a
function until(p, f, x) {
let v = x;
while(!p(v)) v = f(v);
return v;
}
let result1 = unfoldr(
x => {
return {
value: x,
valid: (x % 6) !== 0,
new: x + 1
}
},
1
);
let result2 = until(
m => (m.n % 6) === 0,
m => {
return {
n : m.n + 1,
xs : m.xs.concat(m.n)
};
},
{
n: 1,
xs: []
}
).xs;
return [result1, result2];
})();

View file

@ -0,0 +1 @@
[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]

View file

@ -0,0 +1,20 @@
// generator with the do while loop
function* getValue(stop) {
var i = 0;
do {
yield ++i;
} while (i % stop != 0);
}
// function to print the value and invoke next
function printVal(g, v) {
if (!v.done) {
console.log(v.value);
setImmediate(printVal, g, g.next());
}
}
(() => {
var gen = getValue(6);
printVal(gen, gen.next());
})();

View file

@ -0,0 +1,6 @@
1
2
3
4
5
6