Created
July 15, 2016 21:24
-
-
Save pablohpsilva/2ec5ce8d43eaea59874e7031b7cd7409 to your computer and use it in GitHub Desktop.
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
/** | |
* formatResult receives a value a.k.a. the list being filtered and an array | |
* of filter functions, using the structure I created and mentioned before. | |
* The idea here is to get every item in the array function and use it on | |
* the list. The result list of each filter will be used in the next | |
* round of filters. Keep in mind the structure I used before. | |
*/ | |
export const formatResult = (value, functionArray) => { | |
if (functionArray) { | |
let rList = value, | |
aux = []; | |
for (let i = 0, total = functionArray.length; i < total; i++) { | |
/** | |
* I have to concat the list in the arguments used by | |
* the current function. Why? Simple: because the | |
* list is also an argument of the filter. =D | |
*/ | |
aux = [rList].concat((functionArray[i]).args); | |
rList = (functionArray[i]).func.apply(null, aux); | |
} | |
return rList; | |
} | |
// If there's no filter, just return the list. | |
return value; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment