Day 75: Frequency of Characters from String of 100DaysCodingChallenge
Hello all,
#day75
Day75
Today's my task was to Write a Program to Find the Frequency of every Character from a String using string input taken by the user.
I have started the 100 days of coding challenge to improve my programming skills..
Code :
function count( str , outp_map ) { for( let i = 0 ;i < str.length ;i++) { let k = outp_map.get(str[i]); outp_map.set(str[i], k+1) ; } //calling print function printans(outp_map); } //function create map to count character function count_occurs( test , callback ) { //checking string is valid or not if( test.length === 0 ) { console.log(" empty string "); return ; } else { // map for storing count values let ans = new Map(); for( let i = 0 ;i < test.length;i++) { ans.set(test[i], 0); } callback( test ,ans); } } // test string //let test = "helloworld"; let test = prompt("Enter a String : "); count_occurs( test ,count);
Output :
Happy Coding:)
Thank you...
Comments
Post a Comment