Last active
March 3, 2017 08:50
-
-
Save cronoh/816f1fe0d5fb45b859e24b088725b301 to your computer and use it in GitHub Desktop.
Which is better to read?
This file contains 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
// For context, we have two arrays of routes (['get', '/', ...], ['put', '/:id', ...]) that we are checking for collisions | |
// Then removing the collisions from the base array (actions) | |
// #1 | |
// Remove conflicting routes by filtering out items from the base actions where the first 2 values are equal. Coerce the result of find() to a boolean. | |
actions = actions.filter(a => !actions2.find(a2 => a[0].toLowerCase() === a2[0].toLowerCase() && a[1].toLowerCase() === a2[1].toLowerCase())); | |
// #2 | |
actions = actions.filter(a => { | |
// Search the new actions for a case insensitive match. Coerce the result to boolean, and return the inverse. | |
return !actions2.find(a2 => a[0].toLowerCase() === a2[0].toLowerCase() && a[1].toLowerCase() === a2[1].toLowerCase()) | |
}); | |
// #3 ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment