Skip to content

Instantly share code, notes, and snippets.

@davidvandusen
Forked from kvirani/README.md
Created May 5, 2015 13:16
Show Gist options
  • Select an option

  • Save davidvandusen/945b67f0ac4775e03afd to your computer and use it in GitHub Desktop.

Select an option

Save davidvandusen/945b67f0ac4775e03afd to your computer and use it in GitHub Desktop.

Revisions

  1. David VanDusen revised this gist May 5, 2015. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +0,0 @@
    Create a directory in your `/vagrant` folder (while ssh'd into your Vagrant VM). Within that directory, clone your fork of this repo, which contains one ruby file `max.rb`.

    Spend the time necessary to read and fully understand what the code in `max.rb` is doing. Google or discuss as necessary. Have an expectation of what will be output when you first run the code, then use the ruby command to run the `max.rb` file from the terminal.

    Task: Currently, the built-in `Array#max` method is being used (line 3) to implement the logic for the `maximum` method. As an exercise, instead of leveraging this built-in method, implement your own logic such that the `maximum` method continues to work the same way that it was, and the resulting output from this ruby script stays the same. Note: you also cannot use Ruby's built-in `sort` method.
  2. @kvirani kvirani revised this gist May 4, 2014. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    Create a directory in your `/vagrant` folder (while ssh'd into your Vagrant VM). Within that directory, clone your fork of this repo, which contains one ruby file `max.rb`.

    Spend the time necessary to read and fully understand what the code in `max.rb` is doing. Google or discuss as necessary. Have an expectation of what will be output when you first run the code, then use the ruby command to run the `max.rb` file from the terminal.

    Task: Currently, the built-in `Array#max` method is being used (line 3) to implement the logic for the `maximum` method. As an exercise, instead of leveraging this built-in method, implement your own logic such that the `maximum` method continues to work the same way that it was, and the resulting output from this ruby script stays the same. Note: you also cannot use Ruby's built-in `sort` method.
  3. @kvirani kvirani created this gist Mar 4, 2014.
    18 changes: 18 additions & 0 deletions max.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    # Find the maximum
    def maximum(arr)
    arr.max
    end

    # expect it to return 42 below
    result = maximum([2, 42, 22, 02])
    puts "max of 2, 42, 22, 02 is: #{result}"

    # expect it to return nil when empty array is passed in
    result = maximum([])
    puts "max on empty set is: #{result.inspect}"

    result = maximum([-23, 0, -3])
    puts "max of -23, 0, -3 is: #{result}"

    result = maximum([6])
    puts "max of just 6 is: #{result}"