Last active
February 24, 2017 04:54
-
-
Save rjoydip-zz/0c569394f3340a5352fe6bc1adfee5c4 to your computer and use it in GitHub Desktop.
This is a simple array dimension plugin using constructor pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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