Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. function solution(input) {
  2. let command = input.shift();
  3. let i = 0;
  4. let stepCounter = 0;
  5. let target = 10000;
  6. let res = 0;
  7.  
  8.  
  9. while (command !== "Going home" || stepCounter < target) {
  10. let currentSteps = Number(command);
  11. command = input.shift();
  12. i++;
  13. stepCounter += currentSteps;
  14. res = target - stepCounter;
  15. if(stepCounter>=target){
  16. console.log("Goal reached! Good job!");
  17. }
  18. if (command == "Going home") {
  19. command = input.shift()
  20. res -= command;
  21. console.log(`${res} more steps to reach goal.`)
  22. break
  23. }
  24.  
  25.  
  26.  
  27. }
  28. }
  29. solution([
  30. "125",
  31. "250",
  32. "4000",
  33. "30",
  34. "2678",
  35. "4682",
  36.  
  37. ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement