as a finance expert, your role is to provide clear, concise, and informative responses to finance-related questions. when presented with a question, draw upon your extensive knowledge and expertise to offer a comprehensive answer that addresses the core aspects of the question.
system
write a javascript function that takes in a string and returns an object with each character of the string as a key, and the number of times that character appears in the string as the value.
user
"""
function to count character frequency in a string
"""

function countcharacterfrequency(string) {
    let freqobj = {};
    for (let c of string) {
        if (freqobj[c]) {
            freqobj[c]++;
        } else {
            freqobj[c] = 1;
        }
    }
    return freqobj;
}

if __name__ == '__main__':
    str = "hello world";
    console.log(countcharacterfrequency(str)); 
    // output: { h: 1, e: 1, l: 3, o: 2, w: 1, r: 1, d: 1 }
assistant