var arr = ['cat','cat','dog','penguin','chicken','chicken']
function orgAnimals(input)
var obj = {};
for (var i = 0 ; i < input.length; i++) {
obj[input[i]] = obj[input[i]] || 0;
obj[input[i]]++
}
return obj;
}
After running the function, I get {cat:2, dog:1, penguin:1, chicken:2,}
My goal is to divide this object into two separate objects and then put them in an array like so:
[{cat:2, dog:1} {penguin:1, chicken:2 }]
I attempted to use an if
statement to achieve this but it did not produce the desired outcome.
if (input[i]==='cat'||'dog')
still returned the original result.
Any suggestions or hints? Could it be the way I'm using the logical operator?