Skip to content

Instantly share code, notes, and snippets.

@remy
Created February 21, 2018 15:41
Show Gist options
  • Save remy/92031f44dd7c573e62601c12eb7da8df to your computer and use it in GitHub Desktop.
Save remy/92031f44dd7c573e62601c12eb7da8df to your computer and use it in GitHub Desktop.
Get x/y from index.
console.clear();
const w = 4;
const h = 6;
const res = Array.from({
length: w * h
}, (_, i) => i).map(i => {
const x = i % w;
const y = i / w | 0;
console.log('x/y: %s,%s', x, y);
return { x, y }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment