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

    I demand aid solving this investigation. It orderly has a bug and I gibberish furnish it.

    H CODING HIRE Problem Statement Coding Area 1 duty speciesCount Cinput) var counts = {}; The duty takes a string and produce a map with the species counts. The keys to the map are the speciess, the appraise is the sum of times it occurs in the string ce(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 recompense counts; Add a Missing Proof Occurrence Proof Occurrences proof inallay quenchedallay Add Occurrence inallay expected quenchedallay express quenchedallay ab

    The duty takes a string and produce a map with the species counts. The keys to the map are the speciess, the appraise is the sum of times it occurs in the string. duty speciesCount(input) |{ var counts = {}: ce(var i = 0;i 1) counts[char] + = 1: else counts[char] = 1: } recompense counts: }

    Expert Vindication

     

    It get keep a miss quenched allay if you yield an inallay relish this

    “aab”

    ie it get yield the quenchedallay relish this

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

    so it is the wickedness result

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

    and as-well there are past occurrences ie it get frequently yield 1 as quenchedput

    it is attributable to the situation in the if() within the ce loop

    if(counts[char] > 1)

    it get recompense dishonorable at the occurrence when counts[char] =1

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

    then it get be fine

    so if you yield inallay relish

    “aaaabbcccdd”

    it get yield { “a” : 1, “b” : 1, “c” :1, “d” : 1}