Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function highJump(input) {
- let goalJump = Number(input[0]);
- let index = 1
- let currentJump = Number(input[index]);
- let positiveCounter = 0;
- let negativeCounter = 0
- let currentGoalJump = goalJump - 30;
- let totalJumpCounter = 0
- while (currentJump < goalJump) {
- totalJumpCounter++
- if (currentJump > currentGoalJump) {
- positiveCounter++;
- currentGoalJump += 5;
- negativeCounter = 0;
- } else if (currentJump <= currentGoalJump) {
- negativeCounter++
- }
- index++;
- currentJump = Number(input[index]);
- if (negativeCounter === 3) {
- console.log(`Tihomir failed at ${currentGoalJump}cm after ${totalJumpCounter} jumps.`); return;
- }
- }
- totalJumpCounter++
- console.log(`Tihomir succeeded, he jumped over ${goalJump}cm after ${totalJumpCounter} jumps.`);
- }
- // highJump(["231"
- // , "205"
- // , "212"
- // , "213"
- // , "228"
- // , "229"
- // , "230"
- // , "235"
- // ]);
- highJump(["250"
- ,"225"
- ,"224"
- ,"225"
- ,"228"
- ,"231"
- ,"235"
- ,"234"
- ,"235"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement