DEV Community

Discussion on: Daily Challenge #149 - Fun with Lamps

Collapse
 
elvezpablo profile image
Paul

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);
};