Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://www.hackerrank.com/challenges/jumping-on-the-clouds-revisited/problem
- // declarative
- const jumpingOnClouds = (c, k) => (
- c.reduce(({ energy, ind }, cloud, idx) => (
- idx === ind
- ? cloud === 0
- ? {energy: energy - 1, ind: ind + k}
- : {energy: energy - 3, ind: ind + k}
- : {energy, ind}
- ), {energy: 100, ind: 0}).energy
- )
- // imperative
- function jumpingOnClouds(c, k) {
- let e = 100;
- for (let i = 0; i < c.length; i = i + k) {
- if (c[i] === 0) {
- e = e - 1;
- }
- else {
- e = e - 3;
- }
- }
- return e;
- }
Add Comment
Please, Sign In to add comment