0

To sort a character array in alphabetical order

input: this is a book output: a book is this

5th Feb 2017, 6:54 AM
deepak joshi
deepak joshi - avatar
3 Respuestas
+ 1
Use array.sort() method: e.g. var arr = ["this", "is", "a", " book"]; console.log(arr.sort()); outputs: arr = ["a", "book", " is", "this"] if you want to also arrange in descending character: console.log(arr.sort()); console.log(arr.reverse());
5th Feb 2017, 7:42 AM
Benneth Yankey
Benneth Yankey - avatar
0
I had tried this.It didn't work.
9th Feb 2017, 5:25 AM
deepak joshi
deepak joshi - avatar
0
Which language are you coding with, because the above is JavaScript and works flawlessly.
11th Feb 2017, 12:14 PM
Benneth Yankey
Benneth Yankey - avatar