I tried to phrase my question very carfully because it looks like a duplicate of jQuery function to get all unique elements from an array? and a bunch of other threads. I need to be very clear, I want to get all elements from an array that are not repeated at all. That is, given an array [1,2,3,4,5,1,2,3,5], it should return [4]. In that other thread, I was losing my mind because I didn't understand why they were using the word unique, which means "Being the only one of its kind; unlike anything else." and building functions that return numbers that have been repeated several times, and it was only while asking this question that I came to understand how they interpreted the question. Looking around the net, it appears that that's how everyone is interpreting it.
I feel very close with this code here:
var myArr = [1,2,3,4,5,1,2,3,5];
var unique = myArr.filter(function(value, index, self){
return self.indexOf(value) != index;
});
console.log(unique);
Which returns an array with each value in the array except ones that do not get repeated. If I could just assign the removed elements to unique, I'd be set, but even reading the documentation on filter I am struggling to understand how it works.
I prefer vanilla js, as I'm coding in FreeCodeCamp's environment and I don't know if I can include libraries.