Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #7250
| Newsgroups | comp.lang.ruby |
|---|---|
| Date | 2016-05-18 02:23 -0700 |
| Message-ID | <bfc6c044-e8ff-436d-af00-038742e45c3f@googlegroups.com> (permalink) |
| Subject | Curious about some comments I received on some of my code |
| From | ngw@nofeed.org |
Hi, I recently took a coding challenge for a job, and as part of my application they sent me a coding challenge I had to pass.
Today I received the answer, and I've been rejected. No big deal, I already found a job I like a lot (and part of it will be in Erlang, yay!), but the comments they made over my code left me... baffled. I would like to have if possible a code review (really not a lot of code) and some comments over the issues they point out.
The task was "Write a program that prints a multiplication table of primes numbers."
I will omit the one-liner Thor script that actually generates the thing, and post my implementation.
class Fixnum
def erathostenes
starting_array = (2..self).to_a
starting_array.each_with_index do |n, outer|
(outer..(starting_array.count - 1)).each do |inner|
if Fixnum.erathostenes_sieves?(starting_array[inner], starting_array[outer])
starting_array[inner] = nil
end
end
starting_array.compact!
end
end
def self.erathostenes_sieves?(number, dividend)
number % dividend == 0 && number / dividend != 1
end
end
Here is the class that prints the table:
module FundingCirclePrimeTable
class Table
attr_reader :numbers, :rows
def initialize(count)
@count = count
@numbers = @count.erathostenes
@rows = @numbers.collect {|n| [n] + @numbers.last(@count - 1).map {|i| (i * n).to_s }}
end
def to_s
Terminal::Table.new(headings: @numbers.map(&:to_s).unshift(' '), rows: @rows)
end
end
end
Yes, the attr_reader in the last class isn't needed, I added it for simplicity when writing tests, and at some point I used an each_with_index and forgot about the index, my bad, left some dirty when refactoring, my bad and I count it as a problem in my code.
They told me that "The feedback from the team showed that the tests provided complete coverage, however the code had a few issue regarding naming and organising and contained quite a few clusters of functionality in a few lines."
Also consider I'm not a native english speaker.
What you guys think? Maybe it's because I opened Fixnum?...
TIA,
ngw
Back to comp.lang.ruby | Previous | Next — Next in thread | Find similar
Curious about some comments I received on some of my code ngw@nofeed.org - 2016-05-18 02:23 -0700 Re: Curious about some comments I received on some of my code Robert Klemme <shortcutter@googlemail.com> - 2016-05-21 22:01 +0200 Re: Curious about some comments I received on some of my code "WJ" <w_a_x_man@yahoo.com> - 2016-07-23 23:43 +0000
csiph-web