Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function highJumps(input) {
- let index = 0;
- let jumpTarget = Number(input[index++]);
- let startJump = jumpTarget - 30;
- let counter = 0;
- let fall = 0;
- while (fall !== 3 && startJump <= jumpTarget) {
- let jump = Number(input[index++]);
- if (jump > startJump) {
- startJump += 5;
- fall = 0;
- } else {
- fall++;
- }
- counter++;
- }
- if (startJump <= jumpTarget) {
- console.log(`Tihomir failed at ${startJump}cm after ${counter} jumps.`);
- } else {
- console.log(`Tihomir succeeded, he jumped over ${jumpTarget}cm after ${counter} jumps.`);
- }
- }
- РЕШЕНИЕ СЪС SHIFT():
- function highJumps(input) {
- let jumpTarget = Number(input.shift());
- let startJump = jumpTarget - 30;
- let counter = 0;
- let fall = 0;
- while (fall !== 3 && startJump <= jumpTarget) {
- let jump = Number(input.shift());
- if (jump > startJump) {
- startJump += 5;
- fall = 0;
- } else {
- fall++;
- }
- counter++;
- }
- if (startJump <= jumpTarget) {
- console.log(`Tihomir failed at ${startJump}cm after ${counter} jumps.`);
- } else {
- console.log(`Tihomir succeeded, he jumped over ${jumpTarget}cm after ${counter} jumps.`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement