nikolayneykov

Untitled

Mar 6th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function printList(params) {
  2.     params.pop();
  3.     let kidList = params.shift().split('&');
  4.  
  5.     for (let param of params) {
  6.         let tokens = param.split(' ');
  7.         let command = tokens[0];
  8.         let kidName = tokens[1];
  9.         let index = kidList.indexOf(kidName);
  10.  
  11.         if (command === 'Bad' && index === -1) {
  12.             kidList.unshift(kidName);
  13.         } else if (command === 'Good' && index !== -1) {
  14.             kidList.splice(index, 1);
  15.         } else if (command === 'Rename' && index !== -1) {
  16.             let newName = tokens[2];
  17.             kidList[index] = newName;
  18.         } else if (command === 'Rearrange' && index !== -1) {
  19.             let kid = kidList.splice(index, 1);
  20.             kidList.push(kid);
  21.         }
  22.     }
  23.     console.log(kidList.join(', '));
  24. }
Add Comment
Please, Sign In to add comment