Created
April 26, 2020 15:21
-
-
Save Askadar/f78b85d82146b5a5a256d4e8ed765a26 to your computer and use it in GitHub Desktop.
bizzre iterate function that uses only math to iterate range with a step
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
/** | |
* Creator: Dmitryck MPreobrazhenskiy https://disqus.com/by/dmitryck/ | |
* Description: bizzre iterate function that uses only math to iterate range with a step | |
* Wanted to preserve it for education purposes, | |
* formatted and replaced `~~` with `Math.floor` for simplicity and descriptivness | |
*/ | |
function iterate(a, b, c, fn = console.log){ | |
code = [ | |
function(a, b, c, k){ | |
fn(a + c*k) | |
k++ | |
code[Math.floor((a + c * k) / b)](a, b, c, k) | |
}, | |
function(){ return } | |
]; | |
code[0](a, b + 1, c, 0) | |
} | |
iterate(-3, 10, 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment