Skip to content

Instantly share code, notes, and snippets.

@KanagawaMarcos
Last active November 5, 2018 15:26
Show Gist options
  • Save KanagawaMarcos/20e8cf0cfd2899a1138f5d984481999d to your computer and use it in GitHub Desktop.
Save KanagawaMarcos/20e8cf0cfd2899a1138f5d984481999d to your computer and use it in GitHub Desktop.
My first functional programming code. While doing a Restful API project, I managed to be able to write a very simple functional piece of code by myself. It was a really good feeling for me, given the fact that I was struggling so much at understanding the basics functional programming.
const trimmed_file_names = data.filter((file_name)=>{
return file_name.indexOf('.log') > -1 || ( include_compressed_logs && file_name.indexOf('.gz.b64') > -1);
}).map((file_name)=>{
if(file_name.indexOf('.log') > -1){
// Remove .log extension
return file_name.replace('.log','');
}
// Add on the .gz files
if(file_name.indexOf('.gz.b64') > -1 && include_compressed_logs){
return file_name.replace('.gz.b64','')
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment