-2

What is wrong here?

  def get_some_elements(arr)
      sz=arr.size
      arr2 =Array.new(sz)
      i=0
    j=0
    0.upto(sz-1) do |i,j, arr2|
      arr2[i] =arr[i][j]
      i++
      j++
    end
end

get_some_elements([[2,4,6], [3,5,7], [12,14,16]])

The error messages I get are

10: syntax error, unexpected keyword_end
16: syntax error, unexpected end-of-input, expecting keyword_end
sawa
  • 165,429
  • 45
  • 277
  • 381
beegee Assem
  • 79
  • 1
  • 3
  • 16

1 Answers1

2
  i++
  j++

Remove it, and your code won't have error messages. But you need to re-write it.

Eupatoria
  • 130
  • 1
  • 9
  • 1
    i think the first comment explain this, you need not put it as answer! – Naim Rajiv Jun 23 '15 at 15:36
  • []': no implicit conversion from nil to integer (TypeError) is what I got after removing i++ and j++ – beegee Assem Jun 23 '15 at 15:41
  • 1
    @NaimRajib If it's the answer, then it should go into an answer. Whether or not someone mentioned it in the comments is irrelevant. – Azolo Jun 23 '15 at 16:02
  • @Azolo, I think Naim's point is a comment is sufficient for pointing out a trivial error. Giving an answer that parrots an earlier comment, especially when the problem is obvious, may enhance Reputation, but (imo) is not so good for reputation. – Cary Swoveland Jun 23 '15 at 16:20
  • 1
    @NaimRajib To paraphrase Horton the Elephant, "An answer is an answer, no matter how small." Comments cannot have a checkmark, but answers can. See also: http://meta.stackoverflow.com/questions/251597/question-with-no-answers-but-issue-solved-in-the-comments – Wayne Conrad Jun 23 '15 at 16:54
  • @WayneConrad okay :) – Naim Rajiv Jun 23 '15 at 17:01