Advertisement
bebo231312312321

Untitled

Mar 20th, 2023
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function phoneBook(input){
  2.   let mybook = [];
  3.   let newbook = []
  4.       input.forEach(line => {
  5.          
  6.           let [name,phone] = line.split(" ");
  7.           let book = {
  8.               [name]: phone,
  9.           }
  10.      
  11.           mybook.push(book);
  12.       });
  13.    
  14.       for(let element of mybook) {
  15.     let el=  Object.entries(element)
  16.     newbook.push(el)
  17.       }
  18.       newbook.sort((a,b) => a[0][0].localeCompare(b[0][0])).map(a=>  console.log(`${a[0][0]}`))
  19.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement