面試題3道


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"] 不一樣的變量名數組

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM