Math / Date
Method
example
sumOfDigit
方法
範例
let sumOfDigit =
nums[i].toString()
.split('')
.map(num => Number(num))
.reduce((cur,acc) => cur + acc, 0)Math
Bitwise operators 位元運算子

Date
Last updated
let sumOfDigit =
nums[i].toString()
.split('')
.map(num => Number(num))
.reduce((cur,acc) => cur + acc, 0)
Last updated
let sumOfDigit =
nums[i].toString()
.split('')
.map(num => Number(num))
.reduce((cur,acc) => cur + acc, 0)let sum = 0
while (value) {
sum += value % 10;
value = Math.floor(value / 10);
}function getSumofDigit (value){
let sum = 0
while (value) {
sum += value % 10;
value = Math.floor(value / 10);
}
return sum
}Math.floor(Math.random()*4)// 0 - 3
Math.floor(Math.random()*5)// 0 - 4let number = 9;
number.toString(2); // "1001"// 十轉二
(96).toString(2)
// 二轉十
parseInt('1100', 2). 9 (base 10) = 1001 (base 2)
14 (base 10) = 1110 (base 2)
--------------------------------
14 & 9 (base 10) = 1000 (base 2) = 8 (base 10). 9 (base 10) = 1001 (base 2)
14 (base 10) = 1110 (base 2)
--------------------------------
14 | 9 (base 10) = 1111 (base 2) = 15 (base 10) 9 (base 10) = 1001 (base 2)
14 (base 10) = 1110 (base 2)
--------------------------------
14 ^ 9 (base 10) = 0111 (base 2) = 7 (base 10)所以 [4,1,2,1,2]
4 ^ 1 ^ 2 ^ 1 ^ 2
== 1 ^ 1 ^ 2 ^ 2 ^ 4
== 0 ^ 0 ^ 4
== 4