📌  相关文章
📜  day 8 字典和地图hackerrank解决方案javascript代码示例

📅  最后修改于: 2022-03-11 15:02:39.804000             🧑  作者: Mango

代码示例1
// day 8 dictionaries and maps hackerrank solution javascript
function processData(input) {
  //Enter your code here
  const splitInput = input.split("\n");
  const phoneBookSize = +splitInput[0];
  const inputValue = splitInput.slice(phoneBookSize + 1);
  const mapData = splitInput.slice(1, phoneBookSize + 1).map(item => {
      let obj = {
          name: item.split(" ")[0],
          phoneNumber: item.split(" ")[1]
      }
      return obj;
  });
  
  let phoneBook = [];
  for (let list of mapData) {
      phoneBook[list.name] = list.phoneNumber;
  }

  for (let name of inputValue) {
      if (phoneBook[name]) {
          console.log(`${name}=${phoneBook[name]}`);
      } else {
          console.log('Not found');
      }
  }
}