This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Accepts a function, the function arguments and the | |
| number of attempts and calculates the average runtime | |
| */ | |
| const functionTimer = fn => (...args) => (attempts = 10000) => { | |
| if (!Number(attempts) > 0) return; | |
| let t0, t1, functionResult, timeResult, timesStamps = Array(attempts); | |
| for (let i = 0; i < attempts; i++){ | |
| t0 = performance.now(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const flatSum = (...args) => { | |
| const isFlatArray = array => !array.some(currentValue => Array.isArray(currentValue)) | |
| const flattenArray = array => array.flat() | |
| while (!isFlatArray(args)) { | |
| args = flattenArray(args) | |
| } | |
| return args.reduce((sum, current) => sum + current) | |
| } |
NewerOlder