-4

I'm trying to filter this large dataset down and I've run into a problem.vI'm using the MovieLens uesr ratings dataset and cut it down to about 10000 entries and removed the timestamp column.

The data is stored like ["userId":1,"movieId":1,"rating":1] and I have an array of duplicate values that are most commonly coming up. I want to remove all elements that don't match one of the 8 values in the duplicate list dupList. I don't really use filters that often and I've tried this but it didnt work.

var filtered = movieDataArray.filter(
    function(e) {
        // console.log(e);
        return this.indexOf(e.movieId) < 0;
    },
    dupList
);

I've also tried a few lodash functions, intersect, union, etc. in the vain hope that one of them would work. Any help would be appreciated.

  • I think you are looking for this: https://stackoverflow.com/questions/15125920/how-to-get-distinct-values-from-an-array-of-objects-in-javascript – sk2andy Dec 01 '19 at 20:07

1 Answers1

0

Since you want only those values in the filtered list which have e.movieId present in dupList list and rest should not be included in the filtered list, then you need to change your code a little bit.

Correct implementation:

var filtered = movieDataArray.filter(
    function(e) {
        return this.indexOf(e.movieId) >= 0;
    },
    dupList
);
Ajay Dabas
  • 1,404
  • 1
  • 5
  • 15