Last active
August 29, 2015 14:04
-
-
Save TehShrike/499f133dfcdf449c3456 to your computer and use it in GitHub Desktop.
Store two numbers inside one number
This file contains 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
function singleNumberToXY(number, boardWidth) { | |
var x = number % boardWidth | |
var y = (number - x) / boardWidth | |
return { | |
x: x, | |
y: y | |
} | |
} | |
function test(number, width) { | |
console.log("Number:", number, "Width: ", width, singleNumberToXY(number, width)) | |
} | |
test(10,8) | |
test(12,3) | |
test(6,4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment