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 ๐Ÿ“–

JavaScript sending data between windows

9 Sep, 2022 ยท 4 min read

JavaScript sending data between windows

Using the native payment request JavaScript API

9 Aug, 2022 ยท 8 min read

Using the native payment request JavaScript API