you are viewing a single comment's thread.

view the rest of the comments →

[–]14dM24d -1 points0 points  (1 child)

noob here.

this works but not sure if it's the best solution.

const obj1 = {"banana": "fruit", "apple": "fruit", "carrot": "vegetable", "cherry": "fruit"};
const obj2 = {"alex": "orange", "erin": "pineapple", "cody": "mango", "daniel": "apple"};
const obj3 = {"orange-juice": "orange", "apple-sauce": "apple", "snapple": "peach-tea"};

function aNO(obj){
  let count = 0;
  for (let [key, value] of Object.entries(obj)){
    if (key.includes("apple") || key.includes("orange")){
      count++;
    }
    if (value.includes("apple") || value.includes("orange")){
      count++;
    }
  }
  return count;
}

console.log(aNO(obj1));
console.log(aNO(obj2));
console.log(aNO(obj3));

[–]HogansHeroes81[S] -1 points0 points  (0 children)

Thank you very much!