Navigation

    ask avan logo
    • Register
    • Login
    • Search
    • Categories
    • Unsolved
    • Solved
    1. Home
    2. Mcode19
    M
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 2
    • Best 1
    • Groups 0

    Mcode19

    @Mcode19

    1
    Reputation
    13
    Profile views
    2
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Mcode19 Follow

    Best posts made by Mcode19

    • Remove Duplicates in Ruby Array without Using the uniq Method

      Hi,

      Any help on the following assignment would be appreciated.

      Remove Duplicates
      You are to write a function called unique that takes an array of integers and returns the array with duplicates removed. It must return the values in the same order as first seen in the given array. Thus no sorting should be done, if 52 appears before 10 in the given array then it should also be that 52 appears before 10 in the returned array.

      Assumptions
      All values given are integers (they can be positive or negative).
      You are given an array but it may be empty.
      They array may have duplicates or it may not.
      You cannot use the uniq method on Arrays (don't even try it), or the nub function from Data.List.
      Example
      puts unique([1, 5, 2, 0, 2, -3, 1, 10]).inspect
      [1, 5, 2, 0, -3, 10]

      puts unique([]).inspect
      []

      puts unique([5, 2, 1, 3]).inspect
      [5, 2, 1, 3]
      What We Are Testing
      We are testing basic array usage and knowledge. There are many ways to solve this and advanced users may find faster ways to solve this.

      posted in Ruby on Rails
      M
      Mcode19

    Latest posts made by Mcode19

    • Remove Duplicates in Ruby Array without Using the uniq Method

      Hi,

      Any help on the following assignment would be appreciated.

      Remove Duplicates
      You are to write a function called unique that takes an array of integers and returns the array with duplicates removed. It must return the values in the same order as first seen in the given array. Thus no sorting should be done, if 52 appears before 10 in the given array then it should also be that 52 appears before 10 in the returned array.

      Assumptions
      All values given are integers (they can be positive or negative).
      You are given an array but it may be empty.
      They array may have duplicates or it may not.
      You cannot use the uniq method on Arrays (don't even try it), or the nub function from Data.List.
      Example
      puts unique([1, 5, 2, 0, 2, -3, 1, 10]).inspect
      [1, 5, 2, 0, -3, 10]

      puts unique([]).inspect
      []

      puts unique([5, 2, 1, 3]).inspect
      [5, 2, 1, 3]
      What We Are Testing
      We are testing basic array usage and knowledge. There are many ways to solve this and advanced users may find faster ways to solve this.

      posted in Ruby on Rails
      M
      Mcode19
    • Determine if Integer is Even or Odd in Ruby

      (Create a function (or write a script in Shell) that takes an integer as an argument and returns "Even" for even numbers or "Odd" for odd numbers.)

      def even_or_odd(number)
      if number = (0,2)
      prints even
      else
      if number = (-1,1,7)
      prints odd
      end

      puts (number)

      Does this make sense?

      posted in Ruby on Rails
      M
      Mcode19