Convert PHP code into Ruby!
RSS icon Email icon Home icon
  • sort

    Posted on April 14th, 2009 RubyLove No comments

    Sorts an array with elements arranged from lowest to highest.

    PHP

    $a = array('a', 'b', 'e', 'g', 'c', 'd');
    sort($a);
    print_r($a);
    /*
    Array (
    	[0] => a
    	[1] => b
    	[2] => c
    	[3] => d
    	[4] => e
    	[5] => g
    )
    */

    Ruby

    a = [ "d", "a", "e", "c", "b" ];
    puts a.sort;
    # => ["a", "b", "c", "d", "e"]

    Leave a reply