某公司Boss面试题3道

1,输入:“get1_install2_app3_list4_by5_android6”(每个单词后面总会携带一个数字,只有偶数才删掉),不用循环只用正则怎么实现输出"get1InstallApp3ListBy5Android"?
2,不能使用任何循环控制语句和迭代器的情况下实现一个0到1000的数组赋值。
3,判断两个对象(注意特殊对象的处理)找出不一致的是哪个变量

问题一:

let str = 'get1_install2_app3_list4_by5_android6'

const reg = /(\B(?=(_)?)[02468]?)/g
const res = str.replace(reg, '')

console.log('打印str', res)

问题二:

// 有个  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"] 不一样的变量名数组

猜你喜欢

转载自www.cnblogs.com/memphis-f/p/12512614.html