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 ancient problem!

Who was there first, the chicken or the egg?

JavaScript Chicken or Egg Sort

const array = ['πŸ₯š', 'πŸ”'];
// (2) ["πŸ”", "πŸ₯š"]

There you go, the answer is Chicken!

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

const array2 = ['πŸ”', '🐣', '🐀', 'πŸ₯š'];
// (4) ["πŸ”", "🐣", "🐀", "πŸ₯š"]

Hmm weird? Yes, this 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.

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

TypeORM viewEntity

30 Mar, 2022 Β· 5 min read

TypeORM viewEntity

The Record Utility Type in TypeScript

12 Mar, 2022 Β· 3 min read

The Record Utility Type in TypeScript

Join 1513 devs and subscribe to my newsletter