Skip to content

Instantly share code, notes, and snippets.

@nickserv
Last active August 29, 2015 14:03
Show Gist options
  • Save nickserv/b3d53f15e9e4f6ac84ee to your computer and use it in GitHub Desktop.
Save nickserv/b3d53f15e9e4f6ac84ee to your computer and use it in GitHub Desktop.
Miscellaneous Node utility functions
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