Open karl-project-review opened 6 years ago
Well, if we'd caught just one more suspect, I would consider to just use for loop. :) For three, with relatively easy function definition and limited argument list - I just use my method for readibility sake. Few almost-identical lines makes obvious for me what is different (I can easily ignore "constant" part of line and focus on "variable" parts). But the again, agreed, if there would be more lines or more complicated function, I would also use for loop as described.
For reference, here is your code that calculates the similarity scores:
The redundant lines in this code could be condensed using a loop, like so:
While this technique doesn't save much code when only working with three samples, it could save you more significant time if you were working with a larger sample set, so it is worth keeping this kind of approach in mind.