Skip to content

Instantly share code, notes, and snippets.

View kavitshah8's full-sized avatar

Kavit Shah kavitshah8

  • Adobe
  • Bay Area, CA
View GitHub Profile
'use strict';
function BinarySearchTree() {
this.root = null;
}
BinarySearchTree.prototype.insertNode = function (val) {
var node = {
data : val,
@kavitshah8
kavitshah8 / ticTacToe.cpp
Created March 22, 2021 16:35
Code Sample For Aarjav
#include <stdio.h>
main()
{
int a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int turn = 1;
int pos;
char pos1, pos2, pos3, pos4, pos5, pos6, pos7, pos8, pos9;
char name1[100], name2[100];
@kavitshah8
kavitshah8 / reversePolishNotation.js
Last active October 9, 2020 06:49
Stack Based Interview Questions
function RPN (seq) {
if (seq.length <= 2) {
console.log('Please enter valid RPN');
return;
}
let operands = ['+', '-', '*', '/' ],
stack = [],
i = 0;
@kavitshah8
kavitshah8 / formatNumber.js
Last active October 8, 2020 05:40
Numbers / Math / Puzzles
function formatNumber (num) {
if (typeof num !== 'number') {
console.error('Incorrect value was passed. Please enter a valid number')
return
}
let isNegativeNum
let isFloatingNum
@kavitshah8
kavitshah8 / 2-D-array-fix-2.js
Last active March 17, 2020 10:57
Arrays with one Misc
function createAndInitialize2DArray(size) {
// catch a bug & fix me!
var defaultValue = 0;
var twoDimensionalArray = [];
function initOneDArray() {
var row = [];
for (var i = 0; i < size; i++) {
row.push(defaultValue);
}

To setup your Visual Studio Code to run prettier to reprint the code on File Save follow these steps.

Now when you will save your file it will use ESLint --fix option which will run prettier to reprint entire code. Then it will run ESLint rules to catch the actual bugs in your code. This will also show red squiggly lines with errors.

  • Prettier Error Example: Delete ,eslint(prettier/prettier)
  • ESLint Error Example: Parsing error: Unexpected token {eslint
@kavitshah8
kavitshah8 / bind.js
Last active July 9, 2019 04:35
Frequently Asked Javascript Interview Questions
Function.prototype.bind1 = function (scope) {
let fn = this
let prefixArgs = Array.prototype.slice.call(arguments, 1)
return function() {
let suffixArgs = Array.prototype.slice.call(arguments)
let args = prefixArgs.concat(suffixArgs)
return fn.apply(scope, args)
}
}
@kavitshah8
kavitshah8 / half-pyramid-2.js
Last active November 28, 2018 13:21
Pyramid Patterns
"use strict";
function createHalfPyramid (height) {
for (var i = 1; i <= height; i++) {
var row = '';
for (var j = 1; j <= (height - i); j++) {
row += ' ';
}
@kavitshah8
kavitshah8 / mutiple-entry-points.js
Last active October 28, 2018 17:02
Webpack Configs
var config = {
entry: {
app: addEntryPoint('./src/Router.jsx'),
vendor: ['lodash', 'react', 'react-router', 'react-dom', 'rc-slider']
},
output: {
path: options.devServer ? path.join( __dirname, 'public', 'js') : 'public',
filename: '[name]-[chunkhash].js',
publicPath: '',
class LinkedList {
constructor() {
this.head = null;
}
insertNodeAtTail(val) {
var node = {
data: val,