Skip to content

Instantly share code, notes, and snippets.

View gs-ysingh's full-sized avatar

Yogesh Singh gs-ysingh

View GitHub Profile
function deepCopy(source) {
return deepCopyHelper(source, {});
}
function deepCopyHelper(source, target) {
for(let key in source) {
const value = source[key];
if(typeof value !== "object") {
target[key] = value;
} else {
function kmpSearch(str, pattern) {
var arr = calculatePrefixTable(pattern);
var j = 0;
var i = 0;
var index = -1;
var len = pattern.length;
var strLength = str.length;
while(i < strLength) {
if(str.charAt(i) === pattern.charAt(j)) {
i++;
<link rel="shortcut icon" href="favicon.ico" />
<link rel="apple-touch-icon-precomposed" href="apple-touch-icon.png" />
<link rel="msapplication-TileColor" href="#0074ba" /> 
<link rel="msapplication-TileImage" href="/mstile-144x144.png" />
const HtmlWebPackPlugin = require('html-webpack-plugin');
const autoprefixer = require('autoprefixer');
const path = require('path');
module.exports = {
entry: __dirname + "/src/client/index.js",
devtool: "cheap-eval-source-map",
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'client.bundle.js',
function Cache(maxSize) {
this.data = [];
this.maxSize = maxSize;
this.size = 0;
this.put = function(key, value, ttl) {
if(value.length > this.maxSize) {
throw new Error('string is too large');
}
<input id="inputText" type="text" />
function DataBind(domElement, object) {
this.element = domElement.element;
this.attribute = domElement.attribute;
this.event = domElement.event;
this.value = this.element[this.attribute];
var self = this;
@gs-ysingh
gs-ysingh / plan.js
Last active July 23, 2020 16:37
Must do for frontend
1. https://www.geeksforgeeks.org/top-10-algorithms-in-interview-questions/
2. Dynamic Programming for Coding Interviews: A Bottom-Up Approach to Problem Solving
3. Narasimha karumanchi - Algorithms
4. https://www.hiredintech.com/system-design/
5. Design from https://github.com/jwasham/coding-interview-university
@gs-ysingh
gs-ysingh / interview.js
Last active February 17, 2022 06:13
JS Interview
1. Write poly-fill of Object.create and explain why it worked:
if(typeof Object.create != "function") {
Object.create = function(param) {
var Fun = function(){};
Fun.prototype = param;
return new Fun();
}
}
//index.js
var Project = function() {
this.info = {};
this.setValues = function(info) {
for(var prop in info) {
if(this.info[prop] !== 'undefined') {
this.info[prop] = info[prop];
}
}
};
//index.js
var Project = function() {
this.info = {};
this.setValues = function(info) {
for(var prop in info) {
if(this.info[prop] !== 'undefined') {
this.info[prop] = info[prop];
}