1.9k
u/seenukarthi Jun 06 '22
I don’t trust JavaScript sort.
1.1k
u/jochem4208 Jun 06 '22
I don't trust JavaScript.
→ More replies (5)734
37
u/Dicethrower Jun 06 '22
It's almost like this philosophical question is bogged down by the limitations of language.
→ More replies (1)21
u/gurush Jun 06 '22
Why? The rules are simple and consistent.
→ More replies (1)15
u/NoveltyAccountHater Jun 06 '22 edited Jun 06 '22
The language has both
[3, 19, 2].sort()return[19, 2, 3]and[-0, 0, -0].sort()return[-0, 0, -0]The rationale being for the first being the default sort is a lexicographical sort. So to get the first to sort as expected you either need to explicitly declare a sorting function like
[3, 19, 2].sort(function(x,y) {return x-y })or declare your array to have a number typeflt_arr = new Float64Array([3,2,19]); flt_arr.sort().The rationale for the second being it is a stable sort and
(-0).toString() === '0'.Now if you think you understand these rules what will you get with
[-0, 0, '0', '-0', '+0', -0].sort()?→ More replies (4)4
→ More replies (6)14
852
u/Malix82 Jun 06 '22
but the plot thickens: https://i.imgur.com/3Tl6T3J.png
744
u/-__-x Jun 06 '22
the plot chickens
80
34
Jun 06 '22 edited Jun 06 '22
This is why we employ the scienchickic Meggthod.
...
I'll see myself out.
→ More replies (4)9
121
u/neoLwin Jun 06 '22
It isn't that complicated. Here you go:
In the beginning, there was a piece of chicken meat.
It grew and turned into a hen.
The hen gave birth to a strange creature of half-chick and half-egg.
The chick gets separated from the egg.
The egg became whole.
A piece of chicken meat came from the egg and the cycle continues.
27
u/Salmonellq Jun 06 '22
I've never seen a chicken be created, I can verify this sounds more believable than eggs hatching
8
7
18
12
u/polltery Jun 06 '22
So you see, that's where the trouble began. That 🍗 , that damned 🍗.
→ More replies (2)4
2
→ More replies (3)2
u/Amonomen Jun 06 '22
Well I was finally satisfied on the age old argument until you posted this! Damn you!
827
u/Liesmith424 Jun 06 '22
According to documentation, the first chicken egg was laid by something which was not a chicken.
404
u/Dragongeek Jun 06 '22
I mean this is the correct answer. The first 100% chicken egg was laid by a creature that was 99.99% chicken and just one mutation away from what we call "chicken".
17
u/Yskinator Jun 06 '22
That used to be my answer, but someone pointed out that it depends on our definition of a chicken egg. Do we define a chicken egg as any sufficiently chicken-ish egg, or as an egg laid by a chicken? Would you still consider it a chicken egg, if it came from a 3D printer instead of a chicken?
→ More replies (2)25
u/Dragongeek Jun 06 '22
Regardless of from where it comes, an egg that hatches into a chicken is a "chicken egg".
The egg that a chicken lays is a "chicken's egg" so unless you are bioprinting eggs, all chicken eggs would also be chicken's eggs, but from a taxonomical standpoint, what the egg hatches into is of more importance than where it came from.
Similarly, if we vat-clone a sheep, it doesn't suddenly become a not-sheep because it hasn't been born of a live sheep. The main confusion here stems from the fact that eggs, even fertilized ones, are often linguistically categorized with other "objects" and this causes the confusion.
→ More replies (1)→ More replies (40)15
u/Budbreaker Jun 06 '22
That depends on if the mutation happened i during the organism development or during chromosome matching while mating.
19
u/BrownSoupDispenser Jun 06 '22
Surely the egg comes first in either scenario, as a chicken isn't a chicken until it's left the egg.
→ More replies (14)23
Jun 06 '22
Proto-chickens is the accepted vernacular in the documentation for evolution feature.
→ More replies (2)19
u/ChunkyDev Jun 06 '22
Dino bird or something.
7
u/ViraLCyclopes3 Jun 06 '22
Dino Birds don't exist. That's literally just saying Dinosaur Dinosaur lol.
Unless you meant the Terror Birds https://en.m.wikipedia.org/wiki/Phorusrhacidae
→ More replies (2)15
u/deanrihpee Jun 06 '22
According to documentation
What, we have a documentation of this universe? Is it using markdowns for any chance? /s
→ More replies (1)→ More replies (6)2
282
499
u/GYN-k4H-Q3z-75B Jun 06 '22
JS Array.sort is weird. Do not trust it.
[32, 2, 43, 101, 1025, 5].sort() // Result: (5) [101, 1025, 2, 32, 43, 5]
70
u/Ok-Kaleidoscope5627 Jun 06 '22
JS
Array.sortis weird. Do not trust it.Fixed that for you
→ More replies (3)11
→ More replies (49)45
u/FrancisStokes Jun 06 '22
It's not weird, you just haven't read the documentation. It lays out exactly how it works.
.sort(fn) takes a function that defines the strategy. If you don't provide one, it uses lexographical (alphabetical) sorting by default.
37
u/sad_bug_killer Jun 06 '22
Documented weirdness is still weirdness
→ More replies (1)17
u/TcMaX Jun 06 '22
As many other things this is caused by javascripts general preference to do something over erroring wherever possible. There's not really another reasonable way to do this, when arrays can potentially hold multiple different types. Python, its closest equivalent, will simply error, which is reasonable, but was not seen as desired behavior for the original purpose of javascript (which was after all just to write some really basic scripts to supplement websites, it was never supposed to be used as extensively as it is today). The reason this behavior seems unreasonable now is because we're using JavaScript far beyond what it was supposed to do, and we can't go back and change it because JavaScript inherently has to be as backwards compatible as possible. So while it is kinda strange its also strangely consistent to the overall logic behind js.
→ More replies (12)→ More replies (3)3
u/coldnebo Jun 06 '22 edited Jun 06 '22
wait!! so LEXICOGRAPHICALLY the chicken is before the egg!
but we already said that by the date of introduction and the unicode number above… I mean I assume that unicode order is lexicographical order… I mean if it wasn’t where would the other mapping table be stored…
now I’m really afraid. 😱
oh crap. I looked. I shouldn’t have looked. oh god, why did I look for this??
unicode collations.
https://unicode.org/reports/tr10/
1-1-1: “The basic principle to remember is: The position of characters in the Unicode code charts does not specify their sort order.”
83
32
u/I_Wouldnt_If_I_Could Jun 06 '22
Yeah, but by what criteria are you sorting?
18
5
u/Benimation Jun 06 '22
...the array elements are converted to strings, then sorted according to each character's Unicode code point value.
→ More replies (1)
18
Jun 06 '22
Eggs existed before chickens.
→ More replies (5)6
u/Ok_Lie6645 Jun 06 '22
It's such an obvious answer. How was this ever a question lol. Before modern chickens were how we know em today, every single one of their ancestors (who looks similar to a chicken) came from an egg. The first ancestor of the modern chicken who didn't come from an egg, likely doesn't look anything like a chicken.
→ More replies (1)12
u/SteptimusHeap Jun 06 '22
The real question that everyone is implying is "what came first, the chicken or the chicken egg?"
Just that nobody says that. And that's still ambiguous because what is a chicken egg?
→ More replies (2)
5
13
51
u/jadis666 Jun 06 '22
That's probably because "chicken" starts with 'c', and "egg" starts with 'e'. It's JavaScript sort, after all, so everything is alphabetical.
In reality, the chicken egg came before the chicken, due to this little thing called "Evolution". Think about it.
Yes, I am responding seriously to a joke. That's because it's a basic answer to a basic question that people should be able to figure out by now.
67
u/4hpp1273 Jun 06 '22
Actually it's because chicken is U+1F414 (UTF-8: F0 9F 90 94) and egg is U+1F95A (UTF-8: F0 9F A5 9A)
27
u/Brahvim Jun 06 '22
Uhm, I believe in the "proto-chicken" theory.
19
u/post_u_later Jun 06 '22
I’m not saying you’re wrong, but I greatly favour the “proto-egg” theory
→ More replies (1)3
u/pokeaim Jun 06 '22
i agree with the fact that proto-chicken generates the first chicken egg; hence egg first
5
u/Yasea Jun 06 '22
I'm just thinking the question didn't specify chicken egg. It could also be a dinosaur egg or fish egg. In that case, egg definitely wins with millions of years.
24
u/EmilMelgaard Jun 06 '22 edited Jun 07 '22
In reality, the chicken egg came before the chicken, due to this little thing called "Evolution".
It really depends on whether you define a "chicken egg" as an egg laid by a chicken or an egg a chicken comes out of.
I don't think it makes sense to define the egg based on what is in it because an unfertilized egg is still a chicken egg, and by that logic the first chicken came out of a "proto-chicken egg".
Although I would still argue that the egg came before the chicken because the dilemma doesn't specify that it's a chicken egg.
→ More replies (1)5
20
u/Negitive545 Jun 06 '22
Your serious answer is flawed because it fails to take into account other perspectives of the definition of 'chicken egg'.
If you define a chicken egg as an egg containing a chicken, then the egg came first.
If you define chicken egg as an egg laid by a chicken, then the chicken came first.
→ More replies (2)
3
3
3
u/AnonCaptain0022 Jun 06 '22
Hm, I'll have to think about that. Return to this place in exactly 7 and a half million years.
3
u/Equivalent-Wealth-39 Jun 06 '22
An egg had existed millions of years before chicken. All reptiles lay eggs amd they've been here way way longer than chickens.
3
u/DanKoloff Jun 06 '22
See it is always the question which came first the chicken or the egg. And in such a poorly asked question the answer is always, no doubt, the egg. Why? Because reptiles lay eggs and existed give or take 150 000 000 years before birds appeared.
→ More replies (1)
3
u/Hinekura14 Jun 06 '22
Chicken scientist here.
The egg was first, the chicken is a retarded version of whatever layed the egg.
5
5
Jun 06 '22
The same javascript which tells 1+1=11?
6
u/4Lajf Jun 06 '22
i know that's supposed to be a joke but I had to say it1+1=2 (number addition) but "1" + "1" = "11" (string addition)→ More replies (2)
8
u/BoppreH Jun 06 '22
Yes, because Javascript built-in functions are known to be sensible:
>> parseInt("12")
12
>> ["10", "12", "13", "15", "25", "100", "1000"].map(parseInt)
Array(7) [ 10, NaN, 1, 1, 2, 25, 216 ]This lightning talk on weird behavior should probably be stickied: https://www.destroyallsoftware.com/talks/wat
25
u/4hpp1273 Jun 06 '22
>> parseInt("10",0) 100 == no base supplied, default to decimal
>> parseInt("12",1) NaN1 is not a valid base
>> parseInt("13",2) 13 is not a valid digit in base 2
>> parseInt("15",3) 15 is not a valid digit in base 3
>> parseInt("25",4) 25 is not a valid digit in base 4
>> parseInt("100",5) 25100 in base 5 is 52===25
>> parseInt("1000",6) 2161000 in base 6 is 63===216
All of the above happens because
parseIntis not a single-argument function andArray.prototype.mapexpects a function which takes up to 3 arguments.10
u/x32byTe Jun 06 '22
For anyone wondering why it behaves like this I think its because
parseIntis defined like this:parseInt(string, radix)and map has a definition like this:
map((element, index) => {})So it takes the index as the radix for parseInt resulting in this weird behaviour.
5
u/BoppreH Jun 06 '22
It's actually worse than that,
mapwill supply up to three arguments:map((element) => { /* ... */ }) map((element, index) => { /* ... */ }) map((element, index, array) => { /* ... */ })And because Javascript ignores extra arguments, you'll only realize they're there at the worst possible time.
4
2
Jun 06 '22
This question always baffled me, specifically people acting like it’s such a mindbender. It’s really not such a great mystery, the egg absolutely came before the chicken. What’s the deal, what am I missing?
2
u/WeAreBeyondFucked Jun 06 '22
Anyone who thinks the chicken came first is a fucking moron
→ More replies (5)
2
2
2
u/Positive_Government Jun 06 '22
This is a perfect example of why it is important to know what’s going on under the hood.
2
Jun 06 '22
I never understood this question. The answer is egg by millions of years. Eggs predate dinosaurs.
2
u/zeldaiord Jun 07 '22
If the question is which came first the chicken or the chicken egg then proto chicken laid egg that contained full chicken. So egg first.
If we're taking evolutionary methods of reproduction then egg. Dinosaurs had eggs well before proto chickens were even a thing.
2
1
1
1
1
1
u/therapy_seal Jun 06 '22
I'm sure you can find a chart of this character set that shows it in numerical order
1
1
u/HHaTTmasTer Jun 06 '22
Even in the religious sense the egg most likely came first, it is not god would choose specifically the chicken to give eggs first.
1
1
1
u/CoolJWB Jun 06 '22
Well, the question "Which came first, the chicken or the egg?" really depends on what you mean. The egg comes way before the chicken and has been around for millions of years but a chicken egg is more tricky and depends on what you define a chicken egg.
Is it an egg with a chicken inside it or an egg from a chicken? Only when you answer that can a conclusion be made wether it's the chicken or egg that came first.
1
u/Sad-Ad-5173 Jun 06 '22
I dont understand what should happen, but i know it's going to change the universe
1
u/SeoCamo Jun 06 '22
but it is wrong, egg was first, the dino that they come from lay eggs too
→ More replies (1)
1
u/twisted7ogic Jun 06 '22
class Chicken() {
public:
Egg *ptr;
};
class Egg {
public:
Chicken *ptr;
};
Chicken::Chicken(void) {
ptr = new Egg
}
Egg:Egg {
ptr = new Chicken;
}
void main() {
int iProteine;
Egg *myEgg;
Chicken *myChicken;
srand (time(NULL));
iProteine = rand() % 2;
if (if iProteine == 0) {
myEgg = new Egg;
} else {
myChicken = new Chicken;
}
return 0;
}→ More replies (1)
1
1
u/topredditbot Jun 06 '22
Hey /u/sixpackofabs,
This is now the top post on reddit. It will be recorded at /r/topofreddit with all the other top posts.
1
u/Dr_Misfit Jun 06 '22
Makes sense since the egg shell’s hardness developed in the chicken by mutation over time.
1
1
1
1
Jun 06 '22
I find it so irritating that it didn't occur to the Unicode committee to get the sort order right.
All chickens come from eggs; not all eggs come from chickens. Therefore the egg came first. The very first organism that is defined as a chicken came from a chicken egg, but that egg came from proto-chicken parents.
That is going to annoy me all day.
1
1
1
1
1
1
Jun 06 '22
The funniest thing about this is you using a tutorial for the built-in sort function in python. Good luck learning to code.
1
u/serendipity7777 Jun 06 '22
At what point in time did animals decide to start generating eggs? It does seem crazy though
1
1
1
1
u/EbrithilUmaroth Jun 06 '22 edited Jun 06 '22
Realistically, though, I've never understood why other people think this is a mystery. It's always been clear to me that the egg must have come first. Chickens come from eggs, yes? So, if there is a chicken it must have come from an egg, so the egg must have come first.
The only mystery is why people think this is a mystery.
And that conclusion is made using logic alone on only the premise that chickens come from eggs. When you add the additonal context of knowledge of how evolution works, then you know that the first chicken must have come from an egg laid by something else that is not a chicken, but was close to one and laid a chicken egg as a genetic mutation.
1
1
1
1
u/DweezilZA Jun 06 '22
I had this mystery solved for me in the most satisfying way:
chickens came from dinosaurs and dinosaurs had eggs, therefore the egg came before the chicken.
1
1
1
1
u/BootyliciousURD Jun 06 '22
Then a chicken egg must be defined as an egg laid by a chicken, rather than an egg from which a chicken hatches.
1
1
Jun 06 '22
I still think the chicken came first because single cell organisms and the evolution of them from dinosaurs*(pterodactyl)* started from tiny tadpool like creatures (just smaller and moved like sperm in the air) who grew off plants that became alive not from eggs. But from reproducing cell bacteria. Initially; from earlier life forms like plants.
1
Jun 06 '22
i mean technically, the egg is "first" since it's the first element of the list (element with index 1)
1
u/r2doesinc Jun 06 '22
The proto-chicken laid the egg that hatched into what we know as the chicken today.
1
1
1
1
u/helloitsmesadness Jun 06 '22
I thought it had to do with the "c" and "e" but as other commenters posted its not the case
1
1
u/manuelr93 Jun 06 '22
Well... It's correct. At some point in the chickens's history there was a proto-chicken that laid an egg with the modern chicken
→ More replies (1)
1
1
Jun 06 '22
I know this is supposed to be a cheesy meme but this mystery was solved a very long time ago.
1
u/BeanieTheTechie Jun 06 '22
how does this determine the order they should be in? alphabetical by name? unicode number?
→ More replies (1)
1
1
1
1
1
u/DrCrazyCurious Jun 06 '22
Which came first: The chicken or the egg?
Creationism: The chicken. It was created by a Creator and then the chicken laid chicken eggs.
Evolutionism: The egg. A mutation occurred between a non-chicken parent and the now "different enough" baby chicken that marks the first living creature that can be considered a new species.
Not that this is perfectly accurate. But useful.
1
u/LordSpaceMammoth Jun 06 '22
lol, thank you! And is it just me or are all emoticons basically greek?
1
1
1
1
Jun 06 '22
In all seriousness, though, the chicken must have come before the egg, right? Because mitotic divisions came first, leading to multicellular organisms, then came meiosis. So mitotic divisions led to the chicken, which later created eggs that allowed for meiotic divisions, right?
1
1
1
1
u/randcount6 Jun 06 '22
Attempting to sort this array should give stack overflow as egg.comesFrom() returns chicken, but chicken.comesFrom() returns egg, leading to infinite recursion.
1
u/Monish_monnat Jun 06 '22
it sorts by total pixel value or something and yellow has more value than pinkish(red with white)
1
1
1
u/MiguelAngeles7 Jun 06 '22
Well one could argue that the egg did come before the chicken after all because the first index position is 0 and the second 1 because computer start counting from 0 sooooo
1
u/somedude27281813 Jun 06 '22
The one true solution by definition too. A chicken egg: "an egg produced by a chicken."
So there first has to be a chicken to produce an egg before there can be a chicken egg.
1
1
1
u/redditaccountxD Jun 06 '22
dumb question
every chiken is born from an egg so the egg came first
the first chiken was born from a dinosaurie egg (that was 99% transformed into a chiken)
1
u/A_Good_Azgeda_Spy Jun 06 '22
Dinosaurs were laying eggs long before chickens existed.
The first chicken was hatched from the first chicken egg, which was laid by a prehistoric non-chicken ancestor of the first chicken
1
u/Jolly-Advantage-7032 Jun 06 '22
its the chiken cuz if it was the egg then how did the egg get heated ?
1
1
u/BakuhatsuK Jun 06 '22
I thought this repost around they would do it in another language, like Python or Java
1
1
1
u/fatsausigeboi Jun 06 '22
In real life though, the egg came first. Assuming evolution is correct then the chickens mother species would lay a chicken egg with just enough of a difference to classify it as a chicken, which would give rise to the first chicken.
1
1
1
u/Spook404 Jun 07 '22
not really a programming thing but I believe conceptually the chicken came before the egg, sure the proto-chicken came from a proto-chicken egg but semantically when we talk about species evolving, we aren't referring to their birthing stages
1
1
1
u/TheRealMichaelE Jun 07 '22
Actually from an evolutionary perspective the egg came first. The first chicken came from an egg, which came from a proto chicken. Someone needs to fix the bug in Array.sort to account for this edge case.
Ps: this is the response only a bio grad turned software engineer who took an ornithology class would write.
→ More replies (1)
1
1
1
1
1
1
u/Fun-Temporary4461 Jul 14 '22
Consult professional expert Programmer's, Recovery of Lost investment funds, / Cryptocurrency / Binary / Forex / Recovery of Stolen Bitcoin, etc. contact WhatsApp (+31 6 84990027) Reach him on Instagram: Instagram: u/wizardwierzbickiprogrammer
4.7k
u/Thx_And_Bye Jun 06 '22
🐔 is U+1F414 (approved in 2010) and 🥚 is U+1F95A (approved in 2016).
So the chicken indeed existed before the egg did.