Sort by

recency

|

382 Discussions

|

  • + 0 comments

    function getCount(objects) { return objects.filter(obj => obj.x === obj.y).length; }

  • + 0 comments

    In JS

    function getCount(objects) {
        let count =0
        for(const obj of objects){
            if(obj.x===obj.y){
                count++;
            }
        }
        return count;
    }
    
  • + 0 comments

    function getCount(objects) { let count = 0 const map = objects.map((item) => { if(item.x == item.y){ count +=1 } }) return count }

  • + 0 comments
    function getCount(objects) {
      let count = 0;
    
      for (let i = 0; i < objects.length; i++) {
        const arr = Object.values(objects[i]);
        if (arr[0] === arr[1]) {
          count++;
        }
      }
      console.log("total", count);
      return count;
    }
    
  • + 0 comments

    And just because we can, here is a version using reducer:

    function getCount(objects) {
        return objects.reduce((prev, o) => {
            return prev + (o.x == o.y);
        }, 0);
    }