+ 1

How to short array , like 1 to 10 data[ 8,5,3,9,2,7,1,4,6,10]

Please give solution

10th May 2023, 1:36 AM
kpl Creation
kpl Creation - avatar
14 Answers
+ 4
data.sort();
10th May 2023, 1:44 AM
Orin Cook
Orin Cook - avatar
10th May 2023, 5:08 AM
Ipang
+ 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).
10th May 2023, 7:51 AM
Евгений
Евгений - avatar
+ 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.
10th May 2023, 7:52 AM
Евгений
Евгений - avatar
+ 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)
10th May 2023, 2:42 PM
Ipang
+ 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.
11th May 2023, 8:32 AM
Евгений
Евгений - avatar
+ 1
Print(data.sort())
11th May 2023, 9:51 PM
HÌGHTECH RITESH
+ 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.
11th May 2023, 11:07 PM
Евгений
Евгений - avatar
0
that won't sort numbers correctly, btw, but it should be enough info to let you Google the full solution
10th May 2023, 1:48 AM
Orin Cook
Orin Cook - avatar
0
kpl Creation did any answer here help you?
10th May 2023, 7:57 AM
Евгений
Евгений - avatar
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.
10th May 2023, 12:45 PM
Orin Cook
Orin Cook - avatar
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)
10th May 2023, 4:57 PM
Orin Cook
Orin Cook - avatar
0
You can use bubble short techniques.
11th May 2023, 4:10 AM
Vasudev Verma
Vasudev Verma - avatar
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
11th May 2023, 10:10 PM
Orin Cook
Orin Cook - avatar