zoukankan      html  css  js  c++  java
  • 面试题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"] 不一样的变量名数组
  • 相关阅读:
    一次linux启动故障记录
    linux 时间相关的一些总结
    linux 3.10 gro的理解和改进
    linux 3.10 的中断收包笔记
    一个有趣的nginx问题引发的小问题
    linux 3.10 tcp的accept测试
    linux mce的一些相关内容和用户态监控的设计方法
    C/C++(基础-运算符详解)
    C/C++(基础-常量,类型转换)
    C/C++(基础编码-补码详解)
  • 原文地址:https://www.cnblogs.com/memphis-f/p/12512614.html
Copyright © 2011-2022 走看看