Skip to content

Instantly share code, notes, and snippets.

@rjoydip-zz
Created February 24, 2017 05:08
Show Gist options
  • Save rjoydip-zz/fa0ccd6d09f4a7fc7834860870bd415d to your computer and use it in GitHub Desktop.
Save rjoydip-zz/fa0ccd6d09f4a7fc7834860870bd415d to your computer and use it in GitHub Desktop.
This is a simple array dimension plugin using modular pattern (not like jquery like pattern)
var arrayDimentionObject = {
arrayDimention : arrayDimentionFn,
f1 : f1
};
/*
** 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 arrayDimentionFn(){
var args = Array.prototype.slice.call(arguments);
return (args[0].length === 0) ? args[1]('Array is empty') : args[1](this.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';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment