Last active
August 29, 2015 14:03
-
-
Save nickserv/b3d53f15e9e4f6ac84ee to your computer and use it in GitHub Desktop.
Miscellaneous Node utility functions
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
var fs = require('fs'); | |
// Returns an Array of all directories in the current directory. | |
function getDirectories() { | |
return fs.readdirSync('.').filter(function (file) { | |
return fs.statSync(file).isDirectory(); | |
}); | |
} | |
// Returns a copy of the given Array with all elements of the blacklist Array | |
// removed. | |
function removeBlacklisted(array, blacklist) { | |
return array.filter(function (item) { | |
return blacklist.indexOf(item) === -1; | |
}); | |
} | |
// Returns a flattened Array given an Array of Arrays. | |
function flatten(array) { | |
return array.reduce(function (a, b) { | |
return a.concat(b); | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment