This file contains hidden or 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 car = { | |
drive(){ | |
console.log("Started Driving") | |
}, | |
brake(){ | |
console.log("Stopping the car") | |
}, | |
numofWheels : 4 | |
} |
This file contains hidden or 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 Meal() { | |
this.make = function(builder){ | |
builder.step1(); | |
builder.step2(); | |
builder.step3(); | |
builder.step4(); | |
return builder.get(); | |
} | |
} | |
This file contains hidden or 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 instance = null; | |
class Printer { | |
constructor(pages) { | |
this.display= function(){ | |
console.log(`You are connected to the printer. You want to print ${pages} pages.`) | |
} | |
} | |
static getInstance(numOfpages){ | |
if(!instance){ |
This file contains hidden or 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 Human(name, age, occupation){ //ES5 function based constructor | |
//defining properties inside the constructor function | |
//constructor initializing the property values upon object creation | |
this.name = name; | |
this.age = age; | |
this.occupation = occupation; | |
//defining a method inside the constructor function | |
this.describe = function(){ | |
console.log(`${this.name} is a ${this.age}-year-old ${this.occupation}`); | |
} |
This file contains hidden or 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
// Explanation https://www.youtube.com/watch?v=owZhw-A0yWE | |
#include <vector> | |
#include <iostream> | |
using namespace std; | |
int inv_count = 0; // NAIV, since I didn't want to modify my inital merge sort impelemntation LOL | |
vector<int> merge(vector<int> left, vector<int> right) { | |
vector<int> sortedArray(left.size() + right.size(), 0); |
This file contains hidden or 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
#include <vector> | |
using namespace std; | |
vector<int> merge(vector<int> left, vector<int> right) { | |
vector<int> sortedArray(left.size() + right.size(), 0); | |
int k = 0; | |
int i = 0; | |
int j = 0; | |
while (i < left.size() && j < right.size()) { | |
if (left[i] <= right[j]) { |
This file contains hidden or 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
class IceCreamFactory { | |
constructor() { | |
this.createIcecream = function(flavor) { | |
let iceCream; | |
if (flavor === 'chocolate'){ | |
iceCream = new Chocolate(); | |
} | |
else if (flavor === 'mint'){ | |
iceCream = new Mint(); | |
} |
This file contains hidden or 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
// https://www.youtube.com/watch?v=co4_ahEDCho | |
#include <iostream> | |
#include <unordered_map> | |
#include "minHeap.hpp" | |
using namespace std; | |
// used to store frequency of each caracter | |
unordered_map<char, int> freq; |
This file contains hidden or 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
#include <vector> | |
using namespace std; | |
// Do not edit the class below except for the buildHeap, | |
// siftDown, siftUp, peek, remove, and insert methods. | |
// Feel free to add new properties and methods to the class. | |
class MinHeap { | |
public: | |
vector<int> heap; |
This file contains hidden or 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
#include <iostream> | |
#include <list> | |
using namespace std; | |
//graph class for DFS travesal | |
class DFSGraph { | |
int V; // No. of vertices | |
list<int> *adjList; // adjacency list | |
void DFS_util(int v, bool visited[]) { // heper used by DFS |