{}
run-icon
main.js
// finding the number of character inside a string function getCharCounts (string) { const letterCounts = {} //empty object to hold the value of chars and counts for(let char of string){ //iterating thourgh the string const lowerChar = char.toLowerCase() // to converts the character to lower case if(/[a-z]/.test(lowerChar)){ //checking if it's a character, to avoid whitespace letterCounts[lowerChar] = (letterCounts[lowerChar] || 0) + 1 } } console.log(letterCounts) return letterCounts; } const string = "hello this is sumit, writing a piece of code. writing anythign that can in creatse hrt ecahr ocunts in this string" getCharCounts(string)
Output