vote up 0 vote down
star

i need program in which you enter words via the keyboard or file and then they come out sorted by length using javascript

flag
6 
why don't you write it? – SilentGhost Apr 28 at 15:58

3 Answers

vote up 4 vote down

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.

link|flag
vote up 2 vote down

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

link|flag
vote up 3 vote down

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"]
link|flag
I was about to write the actual function. You beat me to it. +1 – José Basilio Apr 28 at 16:08

Your Answer

Get an OpenID
or

Not the answer you're looking for? Browse other questions tagged or ask your own question.