Advertisement
isebs

Untitled

Feb 24th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. function solve(params){
  2. params.pop();
  3. let kidList=params.shift().split(`&`);
  4. for (let param of params) {
  5. let tokens=param.split(` `);
  6. let command=tokens[0];
  7. let kidName=tokens[1];
  8. let index=kidList.indexOf(kidName);
  9. if(command===`Bad`&&index===-1){
  10. kidList.unshift(kidName);
  11. }else if(command===`Good`&&index!==-1){
  12. kidList.slice(index,1)
  13. }else if(command===`Rename`&&index!==-1){
  14. let newName=tokens[2];
  15. kidList[index]=newName
  16.  
  17. }else if(command===`Rearrange`&&index!==-1){
  18. let kid=kidList.splice(index,1)
  19. kidList.push(kid)
  20. }
  21.  
  22. }
  23. console.log(kidList.join(`, `))
  24. }
  25. solve([
  26. `Peter&George&Mike`,
  27. `Bad Joshua`,
  28. `Good Peter`,
  29. `Finished`,
  30. ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement