Tag: JavaScript

  • Flattening an array in JavaScript

    If you have an mutidementional array(or nested array) you want to flattern, you can do it this way. var flatten = function(array) { var result = [], self = arguments.callee; array.forEach(function(item) { Array.prototype.push.apply( result, Array.isArray(item) ? self(item) : [item] ); }); return result; }; So now you can run it //The result of console.log(flatten([1,2,[3,4,[5,6]]])); //Should […]

  • Making directory along with missing parents in Node.js

    Note: By the time this post is written, the Node.js is on version 0.6.10. Therefore anything in this post may or may not valid in the newer versions. Node.js file system API provide a bunch of functions to read/write files. One of them is the fs.mkdir(path, [mode], [callback]). However, this function itself does not provide […]