Skip to content

Instantly share code, notes, and snippets.

@langjinet
Last active September 20, 2017 02:50
Show Gist options
  • Save langjinet/80a2ef0f2ec9e5da71f0f8606df722a2 to your computer and use it in GitHub Desktop.
Save langjinet/80a2ef0f2ec9e5da71f0f8606df722a2 to your computer and use it in GitHub Desktop.
function declare example, can use Mocha to test and also work with browser
(function( factory ) {
"use strict";
if ( typeof exports === 'object' ) {
// learn how to inject/load other module like jQuery to this module
/*module.exports = function (root, $) {
if ( ! root ) {
// CommonJS environments without a window global must pass a
// root. This will give an error otherwise
root = window;
}
if ( ! $ ) {
$ = typeof window !== 'undefined' ? // jQuery's factory checks for a global window
require('jquery') :
require('jquery')( root );
}
return factory( $, root, root.document );
};*/
module.exports = factory();
}
else {
// Browser
factory(window);
}
} (function(window) {
"use strict";
var getMax = function(valueArrays) {
return valueArrays.map(function(a) {
return (a[0]>a[1])?a[0]:a[1];
});
};
if(window) {
window.getMax = getMax;
} else {
return getMax;
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment