Skip to content

Instantly share code, notes, and snippets.

@rjoydip-zz
Last active February 24, 2017 05:10
Show Gist options
  • Save rjoydip-zz/db6808941958af3ebb40abf3073599e9 to your computer and use it in GitHub Desktop.
Save rjoydip-zz/db6808941958af3ebb40abf3073599e9 to your computer and use it in GitHub Desktop.
This is a simple array dimension library example which is build on like jquery (another kind of modular pattern example)
var fn = (function(){
/*
** This function is deciding whether array is either
** 2D or 1D or array is fully proper array or not.
** @params args taking arguments
** @params arg[0] : Array
** @params arg[1] : callback function
*/
function arrayDimention(){
var args = Array.prototype.slice.call(arguments);
return (args[0].length === 0) ? args[1]('Array is empty') : args[1](f1(args[0]));
}
function f1(arr){
var arrr = [];
for(var i in arr){
arrr.push(Array.isArray(arr[i]));
}
return (arrr.indexOf(true) > -1) ? (arrr.indexOf(false) > -1) ? 'Please check your array' : '2D' : '1D';
}
/* returning public function for the api
** this public function is accessable to user
*/
return {
arrayDimention : arrayDimention
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment