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 2097 devs and subscribe to my newsletter