Skip to content

Instantly share code, notes, and snippets.

@nekoTheShadow
Last active August 29, 2015 14:13
Show Gist options
  • Save nekoTheShadow/47c61eb92fc7f9b029b5 to your computer and use it in GitHub Desktop.
Save nekoTheShadow/47c61eb92fc7f9b029b5 to your computer and use it in GitHub Desktop.
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