Skip to content

Instantly share code, notes, and snippets.

@jonathan-meyer
Created May 24, 2019 15:29
Show Gist options
  • Save jonathan-meyer/28ca2455e43a4b7a6345f6a6a4dbc876 to your computer and use it in GitHub Desktop.
Save jonathan-meyer/28ca2455e43a4b7a6345f6a6a4dbc876 to your computer and use it in GitHub Desktop.
console.log(
[1, "2", 3, 4, "5", true].reduce((p, c, i, a) => {
if (p === null) {
p = Math.floor(Math.random() * a.length);
}
if (typeof p !== "object") {
if (i === p) {
p = [c];
}
}
return p;
}, null)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment