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
var http = require("http"); | |
var { readFileSync } = require("fs"); | |
var path = require("path"); | |
//create a server object: | |
http | |
.createServer(function (req, res) { | |
if (req.method === "GET" && req.url == "/") { | |
const file = readFileSync(path.join(__dirname, "/index.html")); | |
res.writeHead(200, { "Content-Type": "text/html" }); |
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
class Observable { | |
constructor(subscribe){ | |
this._subscribe = subscribe; | |
} | |
subscribe(observer){ | |
return this._subscribe(observer); | |
} | |
static timeout(time){ |
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
// Author: Safiq Lodi | |
//Goal: To find the shortest balanced fragment in a string. | |
/* | |
A balanced string that has equal number of lower and upper case characters. | |
For example - AaBb is a balanced string but TacoCat is not. | |
*/ | |
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
//Goal - To find the number of sub arrays in an array whose sum is 0 | |
const test1 = [1,2,3, -1, -5, -3, -2, 0] | |
function sum0(array) { | |
let subarrays = {} | |
let count = 0; | |
//Iterate over the array to find subarrays corresponding to the value of i |