JSFiddle - React, Tailwind, and code Playground

by Troy Alford

HTML

<code id="output"></code>

JavaScript

const array = [1,3,9,12,27,16,8,2,4]

const separate = (input = []) => input.reduce(
  (all, next) => {
    if (next % 2 === 0) {
      all[1].push(next)
    } else {
      all[0].push(next)
    }

    return all
  },
  [[], []],
)

document.querySelector('#output').innerHTML = JSON.stringify(separate(array))