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

    H CODING HIRE Problem Statement Coding Area 1 estimation estimationCount Cinput) var counts = {}; 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 coercion(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 recur counts; Add a Miscarrying Ordeal Contingency Ordeal Contingencys ordeal inestablish quenchedestablish Add Contingency inestablish expected quenchedestablish developed quenchedestablish ab

    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}