# 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 insufficiency succor solving this inquiry. It orderly has a bug and I jangle furnish it.

The estimation takes a string and receipts a map with the estimation counts. The keys to the map are the estimations, the esteem is the reckon of times it occurs in the string. estimation estimationCount(input) |{ var counts = {}: coercion(var i = 0;i 1) counts[char] + = 1: else counts[char] = 1: } recur counts: }

## Expert Repartee

It procure accept a miscarry quenched establish if you afford an inestablish love this

“aab”

ie it procure afford the quenchedestablish love this

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

so it is the wickedness result

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

and also there are further contingencys ie it procure constantly afford 1 as quenchedput

it is due to the circumstances in the if() internally the coercion loop

if(counts[char] > 1)

it procure recur dishonorable at the contingency when counts[char] =1

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

then it procure be fine

so if you afford inestablish love

“aaaabbcccdd”

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