![H CODING HIRE Problem Statement Coding Area 1 function characterCount Cinput) var counts = {}; 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 for(var i-0;i<input.length;i++) input, charAt(i); 4 var char = if(counts[char] > 1) counts[char] += 1; 7 else counts[char] 1; = 10 return counts; Add a Failing Test Case Test Cases test input output Add Case input expected output actual output ab](https://d2vlcm61l7u1fs.cloudfront.net/media%2F8fe%2F8fe0d405-dc32-4853-ab83-2f855ba00113%2FphpyAazIw.png)
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: }
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}