Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

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