Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
19
Task/Loops-Do-while/JavaScript/loops-do-while-2.js
Normal file
19
Task/Loops-Do-while/JavaScript/loops-do-while-2.js
Normal 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')
|
||||
);
|
||||
6
Task/Loops-Do-while/JavaScript/loops-do-while-3.js
Normal file
6
Task/Loops-Do-while/JavaScript/loops-do-while-3.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
28
Task/Loops-Do-while/JavaScript/loops-do-while-4.js
Normal file
28
Task/Loops-Do-while/JavaScript/loops-do-while-4.js
Normal 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')
|
||||
);
|
||||
5
Task/Loops-Do-while/JavaScript/loops-do-while-5.js
Normal file
5
Task/Loops-Do-while/JavaScript/loops-do-while-5.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
Loading…
Add table
Add a link
Reference in a new issue