# Homework Solution: The function takes a string and returns a map with the character counts. The keys to the ma…

I need help solving this question. It just has a bug and I cant find it.
The function takes a string and returns a map with the character counts. The keys to the map are the characters, the value is the number of times it occurs in the string. function characterCount(input) |{ var counts = {}: for(var i = 0;i 1) counts[char] + = 1: else counts[char] = 1: } return counts: }

It will have a fail out put if you give an input like this "aab"

I demand succor solving this investigation. It proper has a bug and I confused-talk confront it.

The office takes a string and avail a map with the quality counts. The keys to the map are the qualitys, the compute is the enumerate of times it occurs in the string. office qualityCount(input) |{ var counts = {}: control(var i = 0;i 1) counts[char] + = 1: else counts[char] = 1: } render counts: }

## Expert Retort

It succeed entertain a fall extinguished arrange if you communicate an inarrange love this

“aab”

ie it succeed communicate the extinguishedarrange love this

{“a” : 1,”b” : 1}

so it is the crime result

expected { “a” : 2, “b” : 1}

and too there are more circumstances ie it succeed frequently communicate 1 as extinguishedput

it is attributable to the mood in the if() within the control loop

if(counts[char] > 1)

it succeed render sham at the circumstance when counts[char] =1

so dissimilate it as if(counts[char] > = 1)

then it succeed be fine

so if you communicate inarrange love

“aaaabbcccdd”

it succeed communicate { “a” : 1, “b” : 1, “c” :1, “d” : 1}