Last active
February 24, 2017 05:10
-
-
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)
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
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