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
// In the function below changeBy is a private function | |
// whereas increment and decrement are public and hence | |
// can be invoked outside the Counter's scope | |
function Counter(initialCounter) { | |
var privateCounter = initialCounter || 0; | |
function changeBy(val) { | |
privateCounter += val; | |
} | |
return { |
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
/* | |
Let us start with tehse two definitions: | |
Class Variables — Declared inside the class definition (but outside any of the instance methods). They are not tied to any particular object of the class, hence shared across all the objects of the class. Modifying a class variable affects all objects instance at the same time. | |
Instance Variable — Declared inside the constructor method of class (the __init__ method). They are tied to the particular object instance of the class, hence the contents of an instance variable are completely independent from one object instance to the other. | |
Every function created in javascript inherits from Object | |
which internally consists of a constructor function and __proto__ | |
__proto__ allows for sharing across instances | |
*/ |
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 to find triplets with zero sum. | |
/** | |
* @param {number[]} arr | |
* @param {number} n | |
* @returns {boolean} | |
*/ | |
function findTriplets(arr, n) | |
{ |
NewerOlder