Boss face questions of a company 3

1, enter: "get1_install2_app3_list4_by5_android6" (each word always carries behind a number that was only even deleted), not only the regular cycle how to achieve the output "get1InstallApp3ListBy5Android"?
2, array assignment can not be achieved using a 0 to 1000 under any circumstances loop control statements and iterator.
3, determine if two objects (note that special treatment object) to find out which variables are inconsistent

Question one:

let str = 'get1_install2_app3_list4_by5_android6'

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

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

Question two:

// There Array.from (arrayLike [, mapFn [, thisArg]]) method can be used 
the let newArr = Array.from ( new new the Array (1000), (Val, IDX) => {
  return IDX; 
}) 
// Console .log (newArr);

Question three:

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

 

Guess you like

Origin www.cnblogs.com/memphis-f/p/12512614.html