Subscribe

Vanilla JavaScript Chicken or Egg?

✍️

Solving the Chicken vs. Egg with JavaScript

27 Jul, 2020 · 1 min read

I saw this a couple of days ago and thought it was finally a solution to this age-old problem!

Who was there first, the chicken or the egg?

JavaScript Chicken or Egg Sort

const array = ['🥚', '🐔'];
console.log(array.sort());
// (2) ["🐔", "🥚"]

There you go, the answer is Chicken!

But let’s dive deeper and see how this worked out for the egg?

const array2 = ['🐔', '🐣', '🐤', '🥚'];
console.log(array2.sort());
// (4) ["🐔", "🐣", "🐤", "🥚"]

Hmm weird? Yes, this complicates things.

What are your opinions on this Chicken vs. Egg complication?

View the code on Codepen.

See the Pen Vanilla JavaScript Chicken or Egg? by Chris Bongers (@rebelchris) on CodePen.

Thank you for reading, and let’s connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter

Spread the knowledge with fellow developers on Twitter
Tweet this tip
Powered by Webmentions - Learn more

Read next 📖

Removing all vowels with JavaScript

3 Dec, 2022 · 2 min read

Removing all vowels with JavaScript

10 games to learn JavaScript

2 Dec, 2022 · 3 min read

10 games to learn JavaScript

Join 2099 devs and subscribe to my newsletter