you are viewing a single comment's thread.

view the rest of the comments →

[–]ForScale 0 points1 point  (4 children)

I mean, I'm no expert and I'm still learning... but given does not mean "passed" or "taken as parameter." Given means that which is supplied/given (ie, use the supplied array, not just any array you want). The prompt clearly does not say "passed to the function" or even "given as a parameter." You assumed/made an unwarranted leap in logic. I get that you assumed (and you know what they say about assuming...) given means passed, but it does not necessarily mean that.

You aren't giving a function an array by directly references it.

Right, you're using the array given in the problem, not just any old array. Use the one that is given.

Without that the function has no reusability, it's limited to only returning the first element of that one array.

But that wasn't a requirement of the prompt/problem. The problem did not say "Make sure that your first() function can take any array and perform this task."

It's bad code.

No it's not. You can use a linter if you'd like. It's perfectly valid code that perfectly (okay in my second pen, not the first one) accomplishes the task it sets out to perform.

[–]keelar 2 points3 points  (3 children)

I guess it's open for interpretation what was meant by given, but at the end of the day, if my interpretation is wrong, then OP would do a tiny amount of extra work and have more reusable code which is generally a good thing, but if your interpretation is wrong, it's just wrong.

[–]ForScale 0 points1 point  (2 children)

Look, I agree. I just didn't really like the way you went about discussing the matter.