In the above code, the hurdleRace function takes two arguments, k and height. The function returns a number that represents the distance between the current position and the next hurdle. If the height argument is omitted, the function will use the length of the array as the height. The function first checks to see if the height is an empty array. If it is, the function will reduce the height to a fraction and use that as the height. Next, the function checks to see if the height is higher than the k argument. If it is, the function will increase the k argument by the height and return that. Finally, the function returns the target as the final value.

    // Complete the hurdleRace function below.
    function hurdleRace(k, height) {
      return (height || []).reduce((target, hurdle) => {
        (hurdle > k) && (target += hurdle - k);
        (hurdle > k) && (k += hurdle - k);
        return target;
      }, 0);
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.