Skip to content

Instantly share code, notes, and snippets.

View g-akshay's full-sized avatar
🎯
Bullseye

Akshay Gundewar g-akshay

🎯
Bullseye
View GitHub Profile
@g-akshay
g-akshay / memoized function.js
Created September 2, 2024 09:19 — forked from dlucidone/memoized function.js
memoized function
// a simple pure function to get a value adding 10
const add = (n) => (n + 10);
console.log('Simple call', add(3));
// a simple memoize function that takes in a function
// and returns a memoized function
const memoize = (fn) => {
let cache = {};
return (...args) => {
let n = args[0]; // just taking one argument here
if (n in cache) {
@g-akshay
g-akshay / tripplets.js
Created September 2, 2024 09:18 — forked from dlucidone/tripplets.js
tripplets sum
// Time complexity: O(n^2)
function findTriplets(arr, n) {
arr.sort();
var l = arr.length;
for (var i = 0; i < l; i++) {
var j = i + 1,
k = l - 1;
while (j < k) {
if (arr[i] + arr[j] + arr[k] < n) {
j++;
@g-akshay
g-akshay / Problems.md
Last active April 16, 2020 06:12
Data structures

Topics to study

  • DS
    • BFS
    • Hash to count unique
    • Linked List
    • Tree
    • Sorting Algorithms
  • Design
    • stystem design
    • design patterns -> strategy pattern
@g-akshay
g-akshay / details.md
Last active May 22, 2018 07:16
Details about the packages and environment settings required for smooth development on react projects.
  • add a file called .env in the project root with the following contents: NODE_PATH=src/

  • for vs code intellisense: create file jsconfig.json with

{
	"compilerOptions": {
@g-akshay
g-akshay / decorator.md
Created February 22, 2017 15:26
Decorator Pattern
  • aim to promote code re-use
  • offers the ability to add behaviour to existing classes in a system dynamically
  • focuses on the problem of extending objects functionality
@g-akshay
g-akshay / factory.js
Last active February 22, 2017 15:08
Factory Pattern
// Types.js - Constructors used behind the scenes
// A constructor for defining new cars
function Car( options ) {
// some defaults
this.doors = options.doors || 4;
this.state = options.state || "brand new";
this.color = options.color || "silver";
@g-akshay
g-akshay / facade.js
Last active February 22, 2017 15:01
Facade pattern
var myModule = (function() {
var _private = {
i: 5,
get: function() {
console.log( "current value:" + this.i);
},
set: function( val ) {
this.i = val;
},
@g-akshay
g-akshay / mediator.md
Last active February 21, 2017 18:24
Mediator Pattern

Examples

  • A real-world analogy could be a typical airport traffic control system. A tower (Mediator) handles what planes can take off and land because all communications (notifications being listened out for or broadcast) are done from the planes to the control tower, rather than from plane-to-plane. A centralized controller is key to the success of this system and that's really the role a Mediator plays in software design.
  • Another analogy would be DOM event bubbling and event delegation. If all subscriptions in a system are made against the document rather than individual nodes, the document effectively serves as a Mediator. Instead of binding to the events of the individual nodes, a higher level object is given the responsibility of notifying subscribers about interaction events.
@g-akshay
g-akshay / observer.js
Last active December 4, 2019 19:36
Observer Pattern
// skeleton
function Observer(){
this.update = function(){
// ...
};
}
// every observer must have an update method, so that it can do things once notified
@g-akshay
g-akshay / singleton.js
Last active February 21, 2017 17:53
Singleton Pattern
var mySingleton = (function () {
// Instance stores a reference to the Singleton
var instance;
function init() {
// Singleton
// Private methods and variables