Discuss

Discuss

Attached: _20190616_233946.jpg (1080x915, 70K)

Other urls found in this thread:

developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
twitter.com/AnonBabble

this is the reason why highlevel programming shouldn't exist

How about you actually look up the documentation on the standard library.

good god what a piece of shit language
how can anyone even put up with that

What's there to lookup that won't make me conclude JS is dog shit?

>js is retarded on purpose so its ok

Attached: 1305119795741.jpg (281x261, 12K)

Sort compares utf-16 by default due to legacy reasons

All languages have these quirks. Show me a language that doesn't and I'll redirect you to "Your Language Sucks"

It's not retarded at all. Sorting using lexicography order is a reasonable default. If you don't want to use the default, you can provide your own comparison function.

See

The intention was to sort integers, not to have them be converted to strings behind the scenes and then sorted.

you could write your own sorting function...

How the fuck is the language supposed magically know that you intended to sort integers?

>legacy reasons
>on purpose
Blame micro$oft for that

Because the array consists of integers

durr maybe because the list only contains integers.

By having explicit types, which is why anyone who wants to argue that dynamically type languages are better than typed languages need a reality check.

All the time you spent annotating the type could have just been used to provide a comparison function.

>Give a list of integers
>Tell js to sort it
>js returns a list of those integers translated into Chinese and sorting them by number of strokes in the character
>How was js supposed to know how you wanted them sorted????

Attached: Capture-1-1.png (284x188, 131K)

>expecting a string sorting function to sort your ints

Where's the method that sorts integers then?

You can easily figure it out by looking at the documentation.

What is polymorphism

They made a mistake not including int sorting in the first version but they can't just change it now, especially with how little code it takes to provide your own sorting function for that particular purpose

>at the documentation
>You can fix this by providing a "compare function" (See "Parameter Values" below).

Attached: 1340143948703.jpg (265x315, 59K)

>All the time you spent annotating the type
"var x = 10" isn't even shorter than "int x = 10".

Literally an alphabetical sort you mong. Maybe you should've provided a lambda function to compare the items

Go ahead and sort an array of declared variables containing 10, 20, 67, and 2.5 in your language and we'll compare it to javascript

I can't fuckin belive that rhis bullshit is true

Attached: hesdelusional.png (497x576, 212K)

>1 post by this ID
move on lads, JS is a disgusting meme language

In normal languages (interpreted ones too), unquoted numbers are numerical figures, not text.
How is that even a question...

is your IQ double digits?

If you actually read the documentation (developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) you'd see that Array.prototype.sort takes an optional comparator function. If this argument is not specified it defaults to converting elements to strings and comparing unicode code points.

It's intended behavior. Just because you refuse to learn the language doesn't make it shit.

compareFunction [Optional]
Specifies a function that defines the sort order. If omitted, the array elements are converted to strings, then sorted according to each character's Unicode code point value.

>the default behavior doesn't match my preconceived expectations

RTFM asswipe

works fine for me

Attached: js.png (279x64, 2K)

but such behavior obliterates reason man

Then when no comparator is specified it would have to iterate through the elements and find a common base type and decide on how to sort based on that.

I have no idea. What makes you think such a thing?
How is my statement not true?
Take almost any programming language (C, Python...). It would have sorted that list correctly.

Or you do not understand the opposite situation? Can't you see why that sorting is valid when if the numbers are interpreted as characters?

>C hacker syndromes BTFO

This isn't even about being dynamically typed. JS is just a retarded language with retarded default behavior. Python for instance, another dynamically typed language, behaves in a sane fashion and sorts a list of integers as integers and a list of strings as strings.
>>> numbers = [10,2,6,1]
>>> numbers.sort()
>>> numbers
[1, 2, 6, 10]
>>> not_numbers=['10','2','6','1']
>>> not_numbers.sort()
>>> not_numbers
['1', '10', '2', '6']

>>> round(1.5)
2
>>> round(2.5)
2

Thanks God Python is not a retarded language with retarded default behavior.

>>> round(1.5)
2.0
>>> round(2.5)
3.0

PEBKAC

node isn't true highlevel

That is the default rounding method defined in IEEE 754

install rust

Just because it's the expected behavior doesn't mean it's not retarded, right?

There's a reason for that too. You might notice that javascript takes a comparator whereas python takes a key. That's because python uses the < operator for sorting with list.sort whereas javascript uses the comparator for comparison. Had javascript chosen to do the same they'd have the same behavior, but imo at least this is more flexible.

[10, 2, 6, 1].sort((a,b) => a-b);
woooooow that was so hard

>if the documentation says that 2+2=5, then you'd better believe that 2+2=5

Attached: sorts.png (333x65, 3K)

Imagine not ever having sex and complaining about JS on gee.

This. Thread ends here.

>bro you only need to tell the compiler to interpret number literals as numbers and not as hindi
thank u sir for javascript hacks.... much thanks....

wow lol javascript is retarded

Attached: fucking retard.jpg (1440x810, 141K)

the Javascript community doesn't need your street shitting abilities, Rakesh. We're looking for a front-end developer, not a poop scooper.

sir... i got gud angular job okay?.... i can reading documentations and sort is okay....

Angular is outdated, Perkach. We use new technologies because of security and performance reasons. Also, how do you manage to program in Javascript if you can't program in plain english.js?

>how is a language supposed to know you intended to sort integers

Attached: 1560278555242.jpg (1080x834, 90K)

All it does is default object comparison, which in js is to serialize as json and sort alphabetically. If you understand the type system (e.g. you can rub your 2.5 brain cells together) makes perfect sense

Imagine not having the compiler correct common mistakes, and you have to bloat your code just to please your big bubby boy compiler momma

low / high level isn't black and white, it's a scale.
C++ compared to C is high level.
C++ compared to Python is low level.

lol wow the defaults are retarded

Let's see your general defaults, then.

>Maybe you should've provided a lambda function to compare the items
The ability to provide a custom sort is a nice addition to a standard library sorting function, not a fucking necessity in order to do the most basic shit. I am not going to fucking play along with your lambda functional bullshit because your designers were too fucking stupid to figure out that an array of int should not be converted to string before sorting. Fuck dynamic typing, fuck lambdas, fuck functional programming and fuck you.

Yeah you should sort objects by memory address amirite? Fucking imbeciles go write some code instead of larping

>lambdas
>functional programming
What the fuck is a lambda function? Since when is JS functional?

Attached: 56226316_2088106681487708_4057445040942847835_n.jpg (766x919, 79K)

2014. Welcome back from that coma

this is your brain on web development

If you're implying JS is functional, you're delusional. It's a general purpose programming language; it can be written in all sorts of styles, and it has never been purely functional.

Nobody said purely. Stop imagining shit you deodorant huffing retard

>JS is only about web development
Oh, if only you knew.

>this language merely pretends to be retarded

>fuck functional programming
This isn't an insult to JS as it isn't a functional language.

Yes it is. It has streams, functions as first class citizen and higher order functions. Now go have sex incel

why the actual fuck are you returning a boolean from a sorter
this has to be bait, it can't not be

>Now go have sex incel
Already did with your mom. JS is as much of a functional language as it is object oriented.

Based

Congrats you figured out js is multi-paradigm. Want your autism trophy now or later?

And if some retard was doing some retarded object oriented shit in JS you'd say fuck OOP even if the language isn't strictly OOP. It was a reference to functional trappings which JS has and the dumb shit like "just provide a lambda function" that it encourages, not an invitation to a debate in regards to the extent which JavaScript is a functional language.

what the hell is this shit?

>sorting isnt comparison based

>expressing trinary logic as boolean
Jow Forums ladies and gents

>you'd say fuck OOP even if the language isn't strictly OOP
What the fuck? Who the hell would say that?

a sorting function returns an integer of either -1, 0 or 1 based on whether a is greater than, less than or equal to b
not a fucking boolean, which'd get juggled to only 0 or 1 and never -1

I don't get it user. If someone is using the OOP style parts of the language to do dumb OOP shit because they're OOPlets you wouldn't say fuck OOP? Like if someone came in and said "oh please all you need to do is provide your own sort class and override the abstract sort method do you even know how this language works???" you wouldn't tell me that's fucking retarded and blame OOP for making them think that was an acceptable solution?

No?

Believe it or not this is probably the most practical design decision javascript could have made. Sorting by < and instead taking a key instead of a comparator would only make sense if javascript allowed operator overloading in particular for the < operator.

Round to nearest even is expected hardware implementation on ALL platforms in existence. Even standard IEEE libraries for HDLs default to round to nearest even. Stop being dumb. Just because you learned round up in elementary school doesn't mean it was a good idea.

Well then, all I can say is that I am stunned that you don't think that programming paradigm or language design influence the users of the language or that the paradigm/design can subsequently be blamed for the outcomes of this influence.

Attached: 1558223043903.jpg (500x496, 273K)

>annotating
Why does everyone against type systems think Java is the only type system?

sort [10,4,2,8] -- fully type checked

javascript was a mistake

Because they're ignorant retards, generally.