i need program in which you enter words via the keyboard or file and then they come out sorted by length using javascript
+5
A:
You should take a look at the array sort method. You can use it and pass in a function that performs the sorting based on whatever criteria you like.
Sebastian Celis
2009-04-28 15:59:46
+4
A:
The sort method takes a function as a parameter:
var a = ["one", "two", "three", "four", "five"];
a.sort(function(a,b){
return a.length - b.length
});
// returns ["one", "two", "four", "five", "three"]
Borgar
2009-04-28 16:06:44
I was about to write the actual function. You beat me to it. +1
Jose Basilio
2009-04-28 16:08:22