Write a function mostAndLeastFrequent(text) that finds the character that occurs most often in a string and the character that occurs least often.
text is a string. It can be empty.'a' and 'A' are different characters.{ most, least }: most is the character with the highest frequency, least the character with the lowest frequency.{ most: null, least: null }. Use null, not undefined.mostAndLeastFrequent('hello world')Returns { most: 'l', least: 'h' }
mostAndLeastFrequent('abba')Returns { most: 'a', least: 'a' }
mostAndLeastFrequent('')Returns { most: null, least: null }
Asked at Cognizant · Source
mostAndLeastFrequent('hello world'){ most: 'l', least: 'h' }mostAndLeastFrequent(''){ most: null, least: null }Hidden tests run on Submit.