In an arbitrary text, calculate the frequency of occurrence of letters in it. Punctuation marks, spaces, numbers do not take into account. The program should display all letters of the alphabet in order of decreasing frequency of their occurrence. Each letter must be printed once. If any letters occur the same number of times, they are displayed in alphabetical order.

Source data A text length of at least 200 characters. The text can contain capital and small letters, numbers, punctuation marks, spaces, line breaks, quotes. It is guaranteed that all texts used as tests for the problem are literary texts in English or Russian.

Result The table of frequencies of letters of the text in the form of the “letter frequency”, separated by spaces.

Example raw data batat :) result a 2 t 2 b 1

  • 2
    Yes, the problem here is not in javascript, but in the algorithm. - Yura Ivanov

1 answer 1

First you need to remove all whitespace and punctuation, then cycle through the line and make an object of the form symbs[letter]=nums , from the resulting form an array of the form symbs [n] = {letter: nums} and sort it. the result should be something like [{a: 3}, {b: 3}, {c: 1}]. if you need to display in the table, then generate it in any way you want.

to read:

if necessary in Russian, google the terms from the above mentioned articles