I did several interview questions for an online recruitment of a company,

  • 1, input: “get1_install2_app3_list4_by5_android6” (each word back always carry a number, only the even delete), I don’t need to loop only regular how to realize the output “get1InstallApp3ListBy5Android”?
  • 2. An array assignment from 0 to 1000 cannot be implemented using any loop control statements and iterators.
  • 3, determine which variable is inconsistent between two objects (note the handling of special objects), return a similar format: “root variable – parent variable -… – Inconsistent variable “string.

I probably wrote the code, but did not complete it accurately. Then I did not reply 😄😄😄

/ / 1
'get1_install2_app3_list4_by5_android6'.replace(/_\S/g, item => {
  return item.substring(1).toLocaleUpperCase();
});

// 1
Array.from(new Array(1001), (item, index) => index);

// 2
const arr = [];
let timer = setInterval((a)= > {
  if (arr.length <= 1000) {
    arr.push(arr.length);
  } else{ clearInterval(timer); }});/ / the third topic
let arrA = { mm: 434.a: 1.b: 2.c: { c: 1 }, d: 345.df: '32323'.e: null.f: undefined.g: null };
let arrB = { nn: 434.a: 2.b: 2.c: { c: 3 }, d: '345'.dc: '32323'.e: null.f: undefined.g: undefined };
const checkObj = (a, b) = > {
  let returnArr = [];
  let keyArrA = Object.keys(a);
  let keyArrB = Object.keys(b);

  // get the travel set
  let chajiArr = keyArrA
    .concat(keyArrB)
    .filter((item, index, concatArr) = > concatArr.indexOf(item) === concatArr.lastIndexOf(item));

  returnArr = returnArr.concat(chajiArr);

  // fetch the union
  let bingjiArr = Array.from(
    new Set(
      keyArrA
        .concat(keyArrB)
        .filter((item, index, concatArr) = >concatArr.indexOf(item) ! == concatArr.lastIndexOf(item)) ) );for (let itemKey of bingjiArr) {
    let typeOfAVal = typeof a[itemKey];
    let typeOfBVal = typeof b[itemKey];

    if(typeOfAVal ! == typeOfBVal) {// Check whether the types are the same
      returnArr.push(itemKey);
    } else {
      // If it is not object, judge the value directly
      if(typeOfAVal ! = ='object'&& a[itemKey] ! == b[itemKey]) { returnArr.push(itemKey); }// If it is object, judge json.stringify
      // TODO (TODO)
      if (typeOfAVal === 'object' && JSON.stringify(a[itemKey]) ! = =JSON.stringify(b[itemKey])) { returnArr.push(itemKey); }}}return returnArr;
};
console.log(checkObj(arrA, arrB));

Copy the code