/    Sign up×
Community /Pin to ProfileBookmark

descending linear sort problem

i’m trying to write a function for an array and then perform a descending linear sort and print the results to the webpage. I dont know how to do a descending linear sort for an array so any help would be greatly appriciated. all i have so far is this

[code=php]
function desend
{
var myArray = new Array[1,2,4,8,16,32,64,128]

[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterSep 23.2005 — <i>
</i>&lt;script type="text/javascript"&gt;&lt;!--
var myArray = [color=blue][1,2,4,8,16,32,64,128];[/color]
myArray.reverse();
alert(myArray)
//--&gt;&lt;/script&gt;
Copy linkTweet thisAlerts:
@harlemrisinauthorSep 23.2005 — thanks a lot man
Copy linkTweet thisAlerts:
@MjhLkwdSep 23.2005 — [CODE]<HTML>
<Head>
<Script type="text/javascript">

var myArray = new Array('1','128','16','32','2','4','8','64');
var sortedArray = new Array();

function toDescend(a,b){

return b-a;
}

function toAscend(a,b){

return a-b;
}

function sortArray(){

sortedArray = myArray.sort(toDescend);
alert('Descending = '+sortedArray);
sortedArray = myArray.sort(toAscend);
alert('Asceding = '+sortedArray)
}

</Script>
</Head>
<Body>
<input type='button' value='Sort myArray' onclick="sortArray()">
</Body>
</HTML>[/CODE]
×

Success!

Help @harlemrisin 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.18,
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,
)...