var removeDuplicates = function(nums) {
let sorted_arr = [];
for(x in nums){
if(!sorted_arr.includes(nums[x]))
sorted_arr.push(nums[x])
}
console.log( sorted_arr)
return sorted_arr
};
const result = removeDuplicates([1,1,2]);
console.log("result", result);
I/P: [1,1,2] O/P: [ ] stdout: [1,2]
Description: I am trying to create a function which returns a sorted array of numbers with no duplicates. I have created an empty array "sorted_arr" and iterate the "nums" array in which I push a number in the "sorted_arr" if the number is not already present in it. The issue I am facing is when I am returning the "sorted_arr" outside for-loop it is empty; while in console.log, i am getting the the expected result.