What would be the right code when you want to sort the set method? | Sololearn: Learn to code for FREE!
+ 1

What would be the right code when you want to sort the set method?

Based on this code, it says that the sort is not a function, it does not show the sorted newNum variable. Here's the code: let num = [3,6,-2,-5,7,3]; let newNum = new Set(num); newNum.sort(); console.log(newNum); Please correct me if it is wrong logic. Thank you.

1st Sep 2020, 1:51 PM
Jules
Jules - avatar
3 Respuestas
+ 7
Julius The Set object does not have a sort method, but the Array object does, so you have to sort num array before you convert it to a set. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
1st Sep 2020, 2:05 PM
ODLNT
ODLNT - avatar
+ 3
You're welcome.
2nd Sep 2020, 12:21 AM
ODLNT
ODLNT - avatar
0
I see. Thanks, now it works
2nd Sep 2020, 12:19 AM
Jules
Jules - avatar