-
-
Save Santoshah/4c0c6115eb1bcc33e8718b5d4c40f37c to your computer and use it in GitHub Desktop.
Transpiled FilterByIteratee
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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