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;
}
So this gives me {cat:2, dog:1, penguin:1, chicken:2,}
I want to split the object up into 2 different objects and put it in an array so it looks like
[{cat:2, dog:1} {penguin:1, chicken:2 }]
I tried an if statement to make that work but it's not.
if (input[i]==='cat'||'dog') still gives me the same output as before.
Any hints? Am I using the operator incorrectly?
if (input[i]==='cat'||'dog')will always betrue.