javascript - How to create a function that sorts a numeric array and be able swap arrays on the fly? -


this code

        var content = [ 409, 879, 483, 465, 907, 154, 838, 847 ]//the array          var result = content.sort( function( a, b ){ return - b } )//this works          alert( result )//works. want able swap out arrays below          function order( ary )//this function returns undefined, why?         {             ary.sort( function( a, b ){ return - b } )//order numbers least greatest;         }          var result = order( content );          alert( result )//returns undefined 

not sure why order function returns undefined, yet outside of function code works? allow order function accept array when called. , yes i'm newbie.

you should return result

function order( ary ) {     return ary.sort( function( a, b ){ return - b } )//order numbers least greatest; } 

demo: http://jsbin.com/?js,console


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -