Skip to content

Instantly share code, notes, and snippets.

@Santoshah
Forked from nickells/filter-by-iteratee.js
Created May 14, 2018 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Santoshah/4c0c6115eb1bcc33e8718b5d4c40f37c to your computer and use it in GitHub Desktop.
Save Santoshah/4c0c6115eb1bcc33e8718b5d4c40f37c to your computer and use it in GitHub Desktop.
Transpiled FilterByIteratee
"use strict";
// Function definition
var filterByIteratee = function filterByIteratee(array, iteratee) {
// Empty object to store attributes as we encounter them
var previousAttributeNames = {};
return array.filter(function (item) {
// Get the right value
var itemValue = iteratee(item);
// Check if we have already stored this item
if (previousAttributeNames.hasOwnProperty(itemValue)) return false;else {
// Store the item so next time we encounter it we filter it out
previousAttributeNames[itemValue] = true;
return true;
}
});
};
// Usage
var uniqueLinks = filterByIteratee(social_post_link, function (item) {
return item.activity_attributes[0].attribute_value;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment