Skip to content

Instantly share code, notes, and snippets.

@Askadar
Created April 26, 2020 15:21
Show Gist options
  • Save Askadar/f78b85d82146b5a5a256d4e8ed765a26 to your computer and use it in GitHub Desktop.
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
/**
* 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