views:

218

answers:

3

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
+2  A: 

Here's an example on how to Sort an Array in Javascript

Jose Basilio
+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
I was about to write the actual function. You beat me to it. +1
Jose Basilio