Day1
str.charAt(i) 字符串的第i個(gè)字符
arr.push(m);//arr的長度
parseInt(j); //字符轉(zhuǎn)數(shù)字
eg1: 348597 => [7,9,5,8,4,3]
程序
function digitize(n) {
return n.toString().split("").reverse().map(function(i){
return Number(i);
});
}
filter() 用法
filter為數(shù)組中的每個(gè)元素調(diào)用一次 callback函數(shù)肮疗,返回 true 或 等價(jià)于 true 的值 的元素創(chuàng)建一個(gè)新數(shù)組
eg2:Take an array and remove every second element out of that array.
function removeEveryOther(arr){
return arr.filter(function(elem,index){
return index%2===0;
});
}
判斷n是否為整數(shù)
parseInt(n) === n && n > 0
n% 1 === 0;
開平方,
Math.sqrt(n) //n開平方
Math.pow(n,m) //n的m次方
Math.round(n) //與 n 最接近的整數(shù)