• Curious about some comments I received on some of my code

    From ngw@nofeed.org@21:1/5 to All on Wed May 18 02:23:57 2016
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Klemme@21:1/5 to ngw@nofeed.org on Sat May 21 22:01:36 2016
    On 18.05.2016 11:23, ngw@nofeed.org wrote:

    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."

    I find that way too unspecific to comment. What is this supposed to
    mean? If they have something to complain about they should address
    specific items - if only that you can learn from it.

    Also consider I'm not a native english speaker.
    What you guys think? Maybe it's because I opened Fixnum?...

    That method should have gone into Integer if at all.

    Kind regards

    robert

    --
    remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From WJ@21:1/5 to ngw@nofeed.org on Sat Jul 23 23:43:27 2016
    ngw@nofeed.org wrote:

    The task was "Write a program that prints a
    multiplication table of primes numbers."

    require 'prime'

    def prime_mul_table n
    a = Prime.take(n)
    width = (a[-1]**2).to_s.size
    matrix = [" ",*a].zip((a + a.product(a).map{|m,n| m*n}).each_slice(n)).
    map{|x,xs| [x,*xs].map{|x| x.to_s.rjust(width)}.join " "}
    end

    prime_mul_table(12).each{|r| puts r}
    2 3 5 7 11 13 17 19 23 29 31 37
    2 4 6 10 14 22 26 34 38 46 58 62 74
    3 6 9 15 21 33 39 51 57 69 87 93 111
    5 10 15 25 35 55 65 85 95 115 145 155 185
    7 14 21 35 49 77 91 119 133 161 203 217 259
    11 22 33 55 77 121 143 187 209 253 319 341 407
    13 26 39 65 91 143 169 221 247 299 377 403 481
    17 34 51 85 119 187 221 289 323 391 493 527 629
    19 38 57 95 133 209 247 323 361 437 551 589 703
    23 46 69 115 161 253 299 391 437 529 667 713 851
    29 58 87 145 203 319 377 493 551 667 841 899 1073
    31 62 93 155 217 341 403 527 589 713 899 961 1147
    37 74 111 185 259 407 481 629 703 851 1073 1147 1369


    --
    The report card by the American Society of Civil Engineers showed the national infrastructure a single grade above failure, a step from declining to the point where everyday things simply stop working the way people expect them to. --- washingtonpost.com/local/trafficandcommuting/us-infrastructure-gets-d-in-annual-report/2013/03/19/c48cb010-900b-11e2-9cfd-36d6c9b5d7ad_story.html

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)