compareTriplets

    0

    0

    The compareTriplets function compares two arrays, a and b, by iterating over each element and comparing it to the corresponding element in the second array. If the elements are greater than, equal to, or less than each other, the respective element in the arrays is incremented, otherwise the element is incremented in the first array.

    function compareTriplets(a, b) {
      let alice = 0
      let bob = 0
      a.forEach((element, index) => {
        if (element > b[index]) {
          alice++
        } else if (element < b[index]) {
          bob++
        }
      })
      return [alice,bob]
    }
    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.