• 面试题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"] 不一样的变量名数组
  • 相关阅读:
    WPF中的brushes
    com中的线程模式(转)
    线程同步
    WPF线程
    应用程序管理(Application)
    WPF的继承结构树
    HTML技巧100例(一)
    多个网站共用一个空间的超值玩法
    用JavaScript实现浏览器地震效果
    HTML技巧100例(二)
  • 原文地址:https://www.cnblogs.com/memphis-f/p/12512614.html
Copyright © 2020-2023  润新知