Last active
November 16, 2015 18:21
-
-
Save king-panda/82dbe70f9985d786ea75 to your computer and use it in GitHub Desktop.
【JS】数値に関連する様々な計算処理メモ ref: http://qiita.com/kingpanda/items/8d95bc3b32057031a3da
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
/* 数値の桁数を表示 */ | |
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)); | |
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
6 | |
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
/* 整数を逆順に並べ替え */ | |
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)); | |
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
6530549 | |
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
/* 整数を逆順に並べ替え */ | |
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)); | |
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
3628800 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment