1,輸入:“get1_install2_app3_list4_by5_android6”(每個單詞后面總會攜帶一個數字,只有偶數才刪掉),不用循環只用正則怎么實現輸出"get1InstallApp3ListBy5Android"?
2,不能使用任何循環控制語句和迭代器的情況下實現一個0到1000的數組賦值。
3,判斷兩個對象(注意特殊對象的處理)找出不一致的是哪個變量
問題一:
let str2 = 'get1_install2_app3_list4_by5_android6'; let result2 = str2.replace(/\_[a-z]/g, $1 => $1.toLocaleUpperCase()).replace(/[246]|_/g, ''); console.log(result2); // get1InstallApp3ListBy5Android
問題二:
// 有個 Array.from(arrayLike[, mapFn[, thisArg]])方法可以用 let newArr = Array.from(new Array(1000), (val, idx) => { return idx; }) // console.log(newArr);
問題三:
let a = {a: 1, b: 2, c: {c: 1}}; let b = {a: 2, b: 2, c: {c: 3}}; const theObjectValueEqual5 = (a, b) => { let result = []; let aProps = Object.keys(a); let bProps = Object.keys(b); for (let i = 0; i < aProps.length; i++) { let aCompare = a[aProps[i]]; let isExist = false; for (let j = 0; j < bProps.length; j++) { let bCompare = b[bProps[j]]; if (JSON.stringify(aCompare) === JSON.stringify(bCompare)) { isExist = true; break; } } console.log(isExist, aProps[i]) if (!isExist) { result.push(aProps[i]); } } return result; } console.log(theObjectValueEqual5(a, b)); // ["a", "c"] 不一樣的變量名數組