Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- РЕШЕНИЕ С FOR:
- function everest(input) {
- let start = 5364;
- let days = 1;
- for (let i = 0; i < input.length; i++) {
- let sleep = input[i++];
- if (sleep === "END") {
- break;
- } else if (sleep === "Yes") {
- days++;
- if (days === 6) {
- break;
- }
- }
- start += Number(input[i]);
- if (start >= 8848) {
- break;
- }
- }
- if (start < 8848) {
- console.log(`Failed!\n${start}`)
- } else {
- console.log(`Goal reached for ${days} days!`);
- }
- }
- РЕШЕНИЕ С WHILE, SHIFT() И ТЕРНАРЕН ОПЕРАТОР:
- function everest(input) {
- let start = 5364;
- let days = 1;
- while (days !== 6 && input[0] !== "END" && start < 8848) {
- days += input.shift() === "Yes" ? 1 : 0;
- start += Number(input.shift());
- }
- console.log(start < 8848 ? `Failed!\n${start}` : `Goal reached for ${days} days!`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement