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