+ 3

Can any one explain me this theory of sorting an array

let values = [144,248,169,276,340,96,47,24,68,194]; console.log(values) //console.log(values.sort()) values.sort((a,b)=>console.log("a=",a,"b=",b,"a-b=",a-b)) console.log(values)

31st Dec 2019, 5:15 PM
Vinay Govardhanam
Vinay Govardhanam - avatar
2 Antworten
+ 2
I think javascript engine might assuming a-value as b-value and b-value as a-value(like (a, b) => a=248,b=144) instead actual assumption might be (like (a, b) => a=144,b=248)....plz help me i gonna mad by this algorithm or javascript engine...
31st Dec 2019, 5:18 PM
Vinay Govardhanam
Vinay Govardhanam - avatar
+ 1
Oops! I got a answer where it's javascript engine in sololearn app which assuming a-value as b-value and b-value as a-value
31st Dec 2019, 6:03 PM
Vinay Govardhanam
Vinay Govardhanam - avatar