DEV Community

Cover image for Vanilla JavaScript Chicken or Egg?
Chris Bongers
Chris Bongers

Posted on • Originally published at daily-dev-tips.com

Vanilla JavaScript Chicken or Egg?

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

Who was there first the chicken or the egg?

JavaScript Chicken or Egg Sort

var array = ['🥚', '🐔'];
console.log(array.sort());
// (2) ["🐔", "🥚"]
Enter fullscreen mode Exit fullscreen mode

There you go the answer is Chicken!

But let's dive a bit deeper and see how this then worked out for the egg?

var array2 = ['🐔', '🐣', '🐤', '🥚'];
console.log(array2.sort());
// (4) ["🐔", "🐣", "🐤", "🥚"]
Enter fullscreen mode Exit fullscreen mode

Hmm weird? Yes this definitely complicates things right?

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.

Alt Text

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

Oldest comments (0)