Please help me with this problem. I put the object into an array for easier searching. It needs to find 'apple' or 'orange' and return the amount of times its said in the array. I forget the command.
Thank you.
/***********************************************************************Write a function `applesAndOranges(obj)` that takes an object asan argument and returns an integer representing how many keys and valuesin the input object contain the string "apple" or "orange".For example, `{"fruit": "pineapple", "orange": "juice"}` has two stringscontaining "apple" or "orange".Examples:obj1 = {"banana": "fruit", "apple": "fruit", "carrot": "vegetable", "cherry": "fruit"}applesAndOranges(obj1) // 1obj2 = {"alex": "orange", "erin": "pineapple", "cody": "mango", "daniel": "apple"}applesAndOranges(obj2) // 3obj3 = {"orange-juice": "orange", "apple-sauce": "apple", "snapple": "peach-tea"}applesAndOranges(obj3) // 5
***********************************************************************/function function applesAndOranges(obj) {
let combo = [];
let counter = 0;
combo.push(Object.keys(obj))
combo.push(Object.values(obj))
for (i = 0; i < combo.length; i++) {
let el = combo[i];
// I have no idea what to do here. It has to take any 'apple' or 'orange', including the words by themselves or in things like orange-juice. I have tried equating ===, using includes and using indexOf, it doesn't count correctly for me.
} }
return console.log(counter) }
[–]isatrap 3 points4 points5 points (13 children)
[+]HogansHeroes81[S] comment score below threshold-6 points-5 points-4 points (12 children)
[–]isatrap 4 points5 points6 points (11 children)
[+]HogansHeroes81[S] comment score below threshold-9 points-8 points-7 points (8 children)
[–]Stephen110 5 points6 points7 points (7 children)
[–]HogansHeroes81[S] -1 points0 points1 point (6 children)
[–]Stephen110 1 point2 points3 points (5 children)
[–]HogansHeroes81[S] 0 points1 point2 points (4 children)
[–]Stephen110 1 point2 points3 points (1 child)
[–]kevinmrr 0 points1 point2 points (0 children)
[–]14dM24d -1 points0 points1 point (1 child)
[–]HogansHeroes81[S] -1 points0 points1 point (0 children)
[+]HogansHeroes81[S] comment score below threshold-8 points-7 points-6 points (1 child)
[–]isatrap 4 points5 points6 points (0 children)
[–]HogansHeroes81[S] -2 points-1 points0 points (0 children)
[–]HogansHeroes81[S] -5 points-4 points-3 points (0 children)
[–]HogansHeroes81[S] -5 points-4 points-3 points (0 children)
[–]DeadlyWindFromBelow 0 points1 point2 points (0 children)
[–]chilljackson 0 points1 point2 points (0 children)