Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Assignment 4.14</title>
- </head>
- <body style="font-family: consolas;">
- <h3>Write a program to Print Repeated Character of String</h3>
- <hr>
- <script src="text/javascript">
- var userInput = prompt("Enter a String to Count each Characters...");
- var splittedArray = userInput.split('');
- var repeatedCharacter = {};
- for (i = 0; i < splittedArray.length; i++) {
- if (splittedArray[i] in repeatedCharacter) {
- repeatedCharacter[splittedArray[i]]++;
- } else {
- repeatedCharacter[splittedArray[i]] = 1;
- }
- }
- var characterCounter = Object.entries(repeatedCharacter);
- characterCounter = characterCounter.sort();
- for (i in characterCounter) {
- document.write(characterCounter[i][0] + ' - ' + characterCounter[i][1] + '<br>');
- }
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment