Last active
August 29, 2015 14:13
-
-
Save nekoTheShadow/47c61eb92fc7f9b029b5 to your computer and use it in GitHub Desktop.
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
process.stdin.resume(); | |
process.stdin.setEncoding('utf8'); | |
// Here your code ! | |
integer2array = function(int){ | |
var ary = []; | |
while(int !== 0){ | |
ary.push(int % 10); | |
int = Math.floor(int / 10); | |
} | |
return ary.reverse(); | |
} | |
array2integer = function(ary){ | |
var int = 0; | |
var len = ary.length - 1; | |
for(var idx = 0; idx <= len ; idx++){ | |
int += ary[idx] * Math.pow(10,len-idx); | |
} | |
return int; | |
} | |
// == main == | |
console.log(integer2array(1234)); | |
// => [1, 2, 3, 4] | |
console.log(array2integer([2,3,5])); | |
// => 235 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment