javascrip 30 天
真是一個夭壽的挑戰
| Day | Topic | Problem | Status |
|---|---|---|---|
| 1 | Closure | Create Hello World Function | DONE |
| 2 | Closure | Counter | DONE |
| 3 | Closure | Counter II | DONE |
| 4 | Basic Array Transforms | Apply Transform Over Each Element in Array | DONE |
| 5 | Basic Array Transforms | Filter Elements from Array | DONE |
| 6 | Basic Array Transforms | Array Reduce Transformation | DONE |
| 7 | Function input and Output | Function Composition | DONE |
| 8 | Function input and Output | Allow One Function Call | DONE |
| 9 | Function input and Output | Memoize | |
| 10 | Function input and Output | Curry | |
| 11 | Promise | Sleep | DONE |
| 12 | Promise | Promise Time Limit | |
| 13 | Promise | Promise Pool | |
| 14 | Time (setTimeout) | Cache With Time Limit | |
| 15 | Time (setTimeout) | Debounce | |
| 16 | Time (setTimeout) | Throttle | |
| 17 | JSON / Recursion / Important Utilities | JSON Deep Equal | |
| 18 | JSON / Recursion / Important Utilities | Convert Object to JSON String | |
| 19 | JSON / Recursion / Important Utilities | Array of Objects to Matrix | |
| 20 | JSON / Recursion / Important Utilities | Differences Between Two Objects | |
| 21 | JSON / Recursion / Important Utilities | Chunk Array | |
| 22 | JSON / Recursion / Important Utilities | Flatten Deeply Nested Array | |
| 23 | This | Array Prototype Last | DONE |
| 24 | This | Group By | |
| 25 | This | Check if Object Instance of Class | |
| 26 | This | Call Function with Custom Context | |
| 27 | Classes | Event Emitter | |
| 28 | Classes | Array Wrapper | |
| 29 | Generators | Generate Fibonacci Sequence | |
| 30 | Generators | Nested Array Generator |
day-01
https://replit.com/@coreisdontgu/Create-Hello-World-Function#index.js
day-07
因為要反過來抓取 array 中的 function
var compose = function(functions) {
return function(x) {
if(functions.length === 0) return x
let result = x
for(let i = 0; i < functions.length; i++){
result = functions.slice((i+1)*-1)[0](result)
}
return result
}
};
但是也可以用另一種方式,直接透過 for loop 就可以從後面取回來。
return function(x) {
let result = x;
for (let i = functions.length - 1; i >= 0; i--) {
result = functions[i](result);
}
return result;
}