DEV Community

loading...

Discussion on: Daily Challenge #210 - Separate Capitalization

Collapse
fluffynuts profile image
Davyd McColl
function capitalize(str) {
  return str.split("").reduce((acc, cur, i) => {
    const 
      odd = i % 2,
      upper = cur.toUpperCase();
    acc[0] += !odd ? upper : cur;
    acc[1] += odd ? upper : cur;
    return acc;
  }, ["", ""]);
}
Collapse
not_jffrydsr profile image
@nobody

Interesting JS solution....I haven't seen ternary operators used so haphazardly before, I'm not comfortable with them still.