133 reputation
5
bio website
location London
age
visits member for 1 year, 8 months
seen Sep 12 at 10:00

(my about me is apparently blank)


Sep
24
awarded  Autobiographer
Feb
11
awarded  Scholar
Feb
11
accepted Are side-effects in Array's “every”, or “some” bad?
Feb
11
comment Are side-effects in Array's “every”, or “some” bad?
Thanks for the great answer; it's been really helpful :).
Feb
10
awarded  Supporter
Feb
10
comment Are side-effects in Array's “every”, or “some” bad?
.. but see that even with map() I'm having to iterate over the array twice; once to validate, and another to convert. However, using a standard for(;;;) loop, I could do this using one iteration, but I can't find a way to apply every, some, map or filter in this scenario, and perform only one pass, without having undesired-side-effects or otherwise introducing bad-practice.
Feb
10
awarded  Editor
Feb
10
comment Are side-effects in Array's “every”, or “some” bad?
Thanks for your answer. I'm not necessarily trying to modify the elements in place per-se; in my actual code, I'm receiving a JSON-formatted array of objects, so I'm first validating the input if (input.every()), to check that each element is an object (typeof el === "object && el !== null) etc, then if that validates, I want to convert each element into the respective Application Model (which, now you mention map() I could use input.map(function (el) { return new Model(el); });; but not necessarily in place.
Feb
10
revised Are side-effects in Array's “every”, or “some” bad?
added 2 characters in body
Feb
10
awarded  Student
Feb
9
comment Are side-effects in Array's “every”, or “some” bad?
@BenjaminGruenbaum: The mutation is only in the body if I replicate the some or every loop in the if body as well as the if head. If I use only one some or every loop, then the mutation occurs in the every/some body, but the if head. Are you therefore saying that I shouldn't mind about using each/ some twice, or making a point I've entirely missed?
Feb
9
comment Are side-effects in Array's “every”, or “some” bad?
... the same applies for every as well, of course.
Feb
9
comment Are side-effects in Array's “every”, or “some” bad?
@BenjaminGruenbaum: But that's exactly my point. If I use some in my if condition to determine whether a certain element in the array exhibits a certain property, 9/10 I need to operate on that element in my if body; now, as some doesn't tell me which of the elements exhibited the property (just "one did"), I can either use some again in the body (O(2n)), or I can just perform the operation inside the if condition (which is bad, because its a side-effect within the head).
Feb
9
comment Are side-effects in Array's “every”, or “some” bad?
@BenjaminGruenbaum: So doesn't that make them toothless more often than not? 9/10, if I use some, I want to do something with the element, if I use every, I want to do something to all of those elements... some and every don't let me access that information, so either I can't use them, or I have to add side-effects.
Feb
9
comment Are side-effects in Array's “every”, or “some” bad?
Hi, thanks for your answer. Sorry, but either I've misunderstood your answer, or you've misinterpreted the code... everything in my code snippet is within the if condition, with only the return being inside the if's body; obviously I'm talking about the code sample preceeded by "what want to be doing is;...
Feb
9
asked Are side-effects in Array's “every”, or “some” bad?