www.hackerearth.com/problems
For practicing programming
For practicing programming
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| use strict; var module = ( function () { // This cannot be seen outside of the module, so it will not create namespace function aPrivateFunction(z) { return Math.sqrt(z); } // Freezing and sealing are two ways to prevent accidental mutation of the // module after creation. return Object.freeze({ // These are accessible as module.anExportedFunction after the definition anExportedFunction: function (x, y) { return x + aPrivateFunction(y); }, anotherExportedFunction: function (x) { return 2 * x; } }); })(); |
1
2
3
4
5
6
7
8
9
10
| use strict; // Use function to create a local scope and persistent environment ( function () { function aPrivateFunction(z) { return Math.sqrt(z); } // Mutate the global environment this .anExportedFunction = function (x, y) { return x + aPrivateFunction(y); }; this .anotherExportedFunction = function (x) { return 2 * x; }; })(); |