I'm learning how to program in javaScript I was trying to do an exercise where I had to sort the numbers in an array and then delete the ones that are repeated, do the following (I'll leave it below to continue with the explanation), my question is that I did not want to use a loop if I did not use map () to traverse the array but I did not know how to change the position of the array elements to make this comparison number.sort()[i] != number.sort()[i-1]
and be able to store in a new array only one value, the truth I do not know if you can if someone knows
Sorry if I could not explain myself well
using a loop instead of map ():
var number = [1, 9, 3, 1, 7, 4, 6, 6, 7];
var arr = []
var k = 0;
for( let i = 0; i < number.length; i++){
if(number.sort()[i] != number.sort()[i-1]){
arr[k] = number.sort()[i]
k++;
}
}
console.log(parseInt(arr.join("")));
note: later I realized that I could use set ().