Skip to content

Instantly share code, notes, and snippets.

@king-panda
Last active November 16, 2015 18:21
Show Gist options
  • Save king-panda/82dbe70f9985d786ea75 to your computer and use it in GitHub Desktop.
Save king-panda/82dbe70f9985d786ea75 to your computer and use it in GitHub Desktop.
【JS】数値に関連する様々な計算処理メモ ref: http://qiita.com/kingpanda/items/8d95bc3b32057031a3da
/* 数値の桁数を表示 */
var Count = function(e){
var num = e,
digit = 0;
if(num == 0){
return 1;
}else{
while(num !== 0){
num = (num/10) << 0;
digit++;
}
num = digit;
return num;
}
}
console.log(Count(293892));
/* 整数を逆順に並べ替え */
var Reverse = function(e){
var num = e,
digit = 0;
if(num < 0){
return -1;
}else if(num == 0){
return 1;
}else{
while(num > 0){
digit = digit * 10 + num % 10;
num = (num/10) << 0;
}
num = digit;
return num;
}
}
console.log(Reverse(9450356));
/* 整数を逆順に並べ替え */
var Factorial = function(e){
var num = e;
if(num < 0){
return -1;
}else if(num == 0){
return 1;
}else{
return (num * Factorial(num - 1));
}
}
console.log(Factorial(10));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment