Skip to content

Instantly share code, notes, and snippets.

@rjoydip-zz
Last active February 24, 2017 04:54
Show Gist options
  • Save rjoydip-zz/0c569394f3340a5352fe6bc1adfee5c4 to your computer and use it in GitHub Desktop.
Save rjoydip-zz/0c569394f3340a5352fe6bc1adfee5c4 to your computer and use it in GitHub Desktop.
This is a simple array dimension plugin using constructor pattern
function RjLib(){
/*
** returning public function for the api
** this public function is accessable to user
*/
return {
arrayDimention : RjLib.prototype.arrayDimention
}
}
/*
** 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
*/
RjLib.prototype.arrayDimention = function(){
var args = Array.prototype.slice.call(arguments);
return (args[0].length === 0) ? args[1]('Array is empty') : args[1](RjLib.prototype.f1(args[0]));
}
RjLib.prototype.f1 = function(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';
}
var myLib = new RjLib();
myLib.arrayDimention([1,2,3],function(status){
console.log(status);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment