The kangaroo function takes two arguments: x1 and v1, and x2 and v2. It calculates the x1 and x2 coordinates based on the input values and then increments them by the respective values. If the coordinates match, the function returns 'YES'; otherwise, it returns 'NO'.

    function kangaroo(x1, v1, x2, v2) {
    let result = 'NO';
      let x1Pos = x1;
      let x2Pos = x2;
      for (let i = 0; i < 10000; i++) {
        x1Pos += v1;
        x2Pos += v2;
        if (x1Pos === x2Pos) {
          result = 'YES';
      return result;
    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.