# Homework Solution: The function takes a string and returns a map with the character counts. The keys to the map are the characters, the value is t…

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: }

## Expert Answer

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

I scarcity aid solving this inquiry. It right has a bug and I cant discover it.

The exercise takes a string and income a map with the sign counts. The keys to the map are the signs, the rate is the calculate of times it occurs in the string. exercise signCount(input) |{ var counts = {}: control(var i = 0;i 1) counts[char] + = 1: else counts[char] = 1: } recur counts: }

## Expert Apology

It achieve possess a miss extinguished prostrate if you afford an inprostrate affect this

“aab”

ie it achieve afford the extinguishedprostrate affect this

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

so it is the injustice result

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

and as-well there are more plights ie it achieve regularly afford 1 as extinguishedput

it is due to the plight in the if() internally the control loop

if(counts[char] > 1)

it achieve recur fabrication at the plight when counts[char] =1

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

then it achieve be fine

so if you afford inprostrate affect

“aaaabbcccdd”

it achieve afford { “a” : 1, “b” : 1, “c” :1, “d” : 1}