/    Sign up×
Community /Pin to ProfileBookmark

word sort in javascript

hi all,
i would really appreciate if someone can tell me how to go about making a word sort program in javascript.Its a bit urgent,so quick response will be really helpful.Thanks in advance.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@parvinderauthorApr 18.2008 — thanks for the reply but actually i am looking for a sort in for word,rather i should put about making a javasript program that will organize words into alphabetical order,for example,there is an word input space and we would enter two or three lines of sentences and then when we will click the sort button the program should sort the words according to vowels or according to the first letter of that word.
Copy linkTweet thisAlerts:
@JMRKERApr 18.2008 — Modify sort for different order or case (upper/lower) displays.
[code=php]
<html>
<head>
<title> Word Sorter </title>
<script type="text/javascript">
function SortWords() {
var warr = new Array();
var words = document.getElementById('src').value;
words = words.replace(/n|r/g,' ');
warr = words.split(" ");
warr.pop(); // drop blank entry at end of input
warr = warr.sort(); // modify order, case, etc. if desired
return warr.join('n');
}
</script>
</head>
<body>
<h1> Word Sorter </h1>
Enter words to sort:<br>
<textarea id="src" rows="5">
Now is the time for all good men to come to the aid of their country.
</textarea>
<br>
<button id="SortWords"
onClick="document.getElementById('dst').value=SortWords()">Sort Words</button>
<button id="clr"
onClick="document.getElementById('src').value='';document.getElementById('dst').value=''">Clear</button>
<br>
Sorted order:<br>
<textarea id="dst" rows="18"></textarea>
</body>
</html>
[/code]

Hope it gets you started.
×

Success!

Help @parvinder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...