-
3745
-
0
-
let userCheck = /^[a-z][a-z]+\d*$|^[a-z]\d\d+$/i;
-
function stairs(n) { if n < 2 { return 0; } switch (n) { case 2: case 3: case 5: return 1; default: return stairs(n-2) + stairs(n-3) + stairs(n-5); } }
-
function sum(arr, n) { switch (n) { case 0: return 0; case 1: return arr[0]; default: return sum(arr, n - 1) + arr[n-1]; } }
-
function rot13(str) { let res = ""; for (let s of str) { if (!(s <= "Z" && s >= "A")) { res += s; continue; } let sCode = s.charCodeAt(); let encoded = String.fromCharCode(sCode + 13); if (encoded <= "Z" && encoded >= "A") { res += encoded; } else { res += String.fromCharCode(sCode - 13); } } return res; }
-
function palindrome(str) { str = str.trim().toLowerCase(); for (let i of [' ', '_', '.', ',']) { str = str.replace(i, ''); } for (let i = 0; i < str.length; i++) { if (str[i] !== str[str.length - i - 1]) { return false; } } return true; }
以上所有javascript代码均遵循ES6标准
This post belongs to Column 「算法专栏」 .