Although you can easily index an array with -1, 0, 1 too...
-1, 0, 1
I think main idea of this kata is write own method like .permutation.
First, <=> operator returns -1, 0, or 1.
i.e.) scores[:P2] <=> scores[:P1] returns -1 if scores[:P2] < scores[:P1] 0 if scores[:P2] == scores[:P1] 1 if scores[:P2] > scores[:P1]
scores[:P2] <=> scores[:P1]
-1 if scores[:P2] < scores[:P1]
0 if scores[:P2] == scores[:P1]
1 if scores[:P2] > scores[:P1]
Because array index starts from 0, adding 1 is necessary to make a correct index (0, 1, or 2).
You don't need matrices.
Loading collection data...
Although you can easily index an array with
-1, 0, 1
too...I think main idea of this kata is write own method like .permutation.
First, <=> operator returns -1, 0, or 1.
i.e.)
scores[:P2] <=> scores[:P1]
returns-1 if scores[:P2] < scores[:P1]
0 if scores[:P2] == scores[:P1]
1 if scores[:P2] > scores[:P1]
Because array index starts from 0, adding 1 is necessary to make a correct index (0, 1, or 2).
You don't need matrices.