Advertisement
Guest User

Untitled

a guest
Oct 29th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. function froggySquad(arr) {
  2.  
  3. let output = '';
  4. let names = arr.shift().split(' ');
  5. for (let iterator of arr) {
  6. let command = arr.shift().split(' ');
  7. let firstWord = command.shift();
  8. let secondWord = command.shift();
  9.  
  10.  
  11. if (firstWord === 'Join') {
  12. names.push(secondWord);
  13. } else if (firstWord === 'Jump') {
  14. let num = command.shift();
  15. if (num >= 0 && num < arr.length) {
  16. names.splice(Number(num), 0, secondWord);
  17. }
  18. } else if (firstWord === 'Dive') {
  19. let num = Number(secondWord);
  20. if (num >= 0 && num < arr.length) {
  21. names.splice(num, 1)
  22. }
  23. } else if (firstWord === 'First') {
  24. let count = Number(secondWord);
  25. if (count <= names.length) {
  26. console.log(names.slice(0, count).join(' '));
  27. }
  28. } else if(firstWord === 'Last'){
  29. let count = Number(secondWord);
  30. if (count <= names.length) {
  31. console.log(names.slice(names.length - 3).join(' '));
  32. }
  33.  
  34. } else if (firstWord === 'Print') {
  35. if (secondWord === 'Reversed') {
  36. output = `Frogs: ${names.reverse().join(' ')}`;
  37.  
  38. } else if(secondWord === 'Normal'){
  39. output = `Frogs: ${names.join(' ')}`;
  40.  
  41. }
  42. }
  43. console.log(output)
  44. }
  45.  
  46.  
  47.  
  48. }
  49.  
  50. //froggySquad(['Blake Muggy Kishko', 'Join Kvachko', 'Dive 0', 'First 10', 'Print Reversed']);
  51. froggySquad(['A B C D E F', 'Join G', 'Jump Q 3', 'Last 3', 'Dive 2', 'Print Normal']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement