Given the text (string), which contains groups of letters, numbers, characters. Convert text by sorting each group of letters alphabetically, each group of numbers in descending order. For example: "cba1076 / 'abfc3785,' '3946f" - "abc7610 /' abcf8753, '' 9643f". Do not use string functions

  • What happened so far? Add your code directly to the question. - 0xdb

1 answer 1

All you need is to split the string into an array and use some sorting. for example

var myString = 'cba1076 /'abfc3785,''3946f'; function myBubbleSort(myArray) { var n = myArray.length; for (var i = 0; i < n-1; i++) { for (var j = 0; j < n-1-i; j++) { if (myArray[j+1] < myArray[j]) { var t = myArray[j+1]; myArray[j+1] = myArray[j]; myArray[j] = t; } } } return myArray; } var myResult = myBubbleSort(myString.split('')); alert(myResult); 

  • As far as I understood from the condition, String.split cannot be used. You can loop through the string, referring to each letter by index (as when working with an array). - Beast Winterwolf