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. 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
    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 "aab"

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

    H CODING HIRE Problem Statement Coding Area 1 office qualityCount Cinput) var counts = {}; 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 control(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 render counts; Add a Falling Cupel Circumstance Cupel Circumstances cupel inarrange extinguishedarrange Add Circumstance inarrange expected extinguishedarrange express extinguishedarrange ab

    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}