Count the recurrence of a word

I wont give you finished code ( thats not the sense of a homework) , but i try to get you to solve the problem on your own.

So far you’ve already got an array of words.

Next lets declare an object we can assign the properties later.

Then we’ll iterate over our array and if the array element doesnt exist in our object as key yet ( if(!obj[array[i]])) well create a new property, with elements name and the value 1.( obj[array[i]=1; )

If the element is a key of that object, lets increase its value.
( obj[array[i]]++;)

Then return the object.

Browse More Popular Posts

Leave a Comment