Skip to main content

Command Palette

Search for a command to run...

Vanilla JavaScript Chicken or Egg?

Published
β€’1 min read
Vanilla JavaScript Chicken or Egg?
C

I'm a full-stack developer from South Africa πŸ‡ΏπŸ‡¦. I love writing about JavaScript, HTML and CSS.

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) ["πŸ”", "πŸ₯š"]

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) ["πŸ”", "🐣", "🐀", "πŸ₯š"]

Hmm weird? Yes this definitely complicates things right?

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

View the code 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

More from this blog

D

Daily Dev Tips

887 posts

Looking to get into development? As a full-stack developer I guide you on this journey and give you bite sized tips every single day πŸ‘Š