A variation on the javascript solution. Opted for a bit more verbosity for ease of understanding. Would love feedback as I get my coding skills back into shape.
const lamps = ary => { return ary.reduce((acc, curr, idx) => { const startsWithZero = ary[0] === 0; const isEven = idx % 2 === 0; const correctValue = (startsWithZero && !isEven) || (!startsWithZero && isEven) ? 1 : 0; return correctValue !== curr ? (acc += 1) : acc; }, 0); };
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
A variation on the javascript solution. Opted for a bit more verbosity for ease of understanding. Would love feedback as I get my coding skills back into shape.