Sha256: 219aaf9f825dbba8810c650f1b1e1e3076919a9a50d8b2cbeaf1beb07452679b

Contents?: true

Size: 1.08 KB

Versions: 396

Compression:

Stored size: 1.08 KB

Contents

class ListOps
  ## Do not use the functions map, concat, count, length, etc.
  ## and other built in ruby methods to solve  these
  ##
  def self.arrays(arr)
    counter = 0
    arr.each do
      counter += 1
    end
    counter
  end

  def self.reverser(arr)
    answer = []
    until arr.empty?
      answer << arr.pop
    end
    answer
  end

  def self.concatter(arr1, arr2)
    answer = []
    arr1.each do |element|
      answer << element
    end
    arr2.each do |element|
      answer << element
    end
    answer
  end

  def self.mapper(arr)
    answer = []
    arr.each do |element|
      answer << yield(element) if block_given?
    end
    answer
  end

  def self.filterer(arr)
    answer = []
    arr.each do |element|
      answer << element if block_given? && yield(element)
    end
    answer
  end

  def self.sum_reducer(arr)
    total = 0
    arr.each do |element|
      total += element
    end
    total
  end

  def self.factorial_reducer(arr)
    total = 1
    arr.each do |element|
        total = total * element
    end
    total
  end
end

module BookKeeping
  VERSION = 2
end

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.179 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.178 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.177 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.176 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.175 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.174 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.173 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.172 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.171 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.170 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.169 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.167 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.166 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.165 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.164 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.163 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.162 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.161 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb
trackler-2.2.1.160 tracks/ruby/exercises/list-ops/.meta/solutions/list_ops.rb