+ 1
How to short array , like 1 to 10 data[ 8,5,3,9,2,7,1,4,6,10]
Please give solution
14 ответов
+ 4
data.sort();
+ 4
Read the reference and you can do it by yourself
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
+ 1
Orin Cook If your solution doesn't work correctly, then why do you propose that? Even if you made a disclaimer. It's very confusing for a novice (not just the topic starter, but for future readers too).
+ 1
I wonder who are those four upvoters? I guess the people who don't know javascript. The Ipang's answer should be upvoted and marked as the accepted answer.
+ 1
Orin Cook wrote:
"Ipang's answer is the same answer, it just bypassed Google"
I don't rely on a particular search engine ...
"(which in this case isn't necessarily a good thing, since the technical reference is probably the least readable answer)."
Did you just claim your answer be more readable? in what way though?
MDN is a reputable reference provider, it's disrespectful to say their documentation is *least readable* when even professional coders recognize MDN's credibility as reference.
(Edited)
+ 1
No, never use bubble sort. This is also a very bad advice. The purpose of bubble sort is only for giving a person a basic foundation in creating algorithms, this is the most inefficient algorithm and it should never be used in the real world.
+ 1
Print(data.sort())
+ 1
HÌGHTECH RITESH You don't read, just write, right? :) It was already discussed, that sort() gives wrong results for numbers. And there's no Print() in JS.
0
that won't sort numbers correctly, btw, but it should be enough info to let you Google the full solution
0
kpl Creation did any answer here help you?
0
Ipang's answer is the same answer, it just bypassed Google (which in this case isn't necessarily a good thing, since the technical reference is probably the least readable answer).
Also you don't have to wonder, you can just click the number.
0
no I'm saying other Google results would be more readable for a beginner. w3 or StackOverflow, for example.
(side note: I intend "Google" here in the generic sense, obviously other search engines would work too)
0
You can use bubble short techniques.
0
As I said above, sort() won't work naively here; it sorts in "ascii-betical" order, so you'd get 1, 10, 2....
You've gotta define a sorting function for it if you want something else