I am working on the Leetcode in JS,
Question 26th (Remove Duplicates from Sorted Array)
I am trying with Set (ES6), but it is not working on the Leetcode page (for direct submitting), however it's working in the console.
Besides, I also found the old answers have already listed Set as a solution. Here's old post!
From the old post, the author said:
ES6 provides the Set object, which makes things a whole lot easier
// code from the old post
function uniq(a) {
return Array.from(new Set(a));
}
or
let uniq = a => [...new Set(a)];
Here are my codes with Set:
//this is my code with Set
var removeDuplicates = function(nums) {
let set = new Set(nums);
let setArr = [...set];
return setArr;
};
And here is what is displayed after code run on Leetcode page,the output is different from the expected:
And here is the display on a webpage's console
Could anyone help me to understand what are the reasons behind? Or I just misunderstood the question? Thank you!