Skip to content

Instantly share code, notes, and snippets.

View tejzpr's full-sized avatar

Tejus tejzpr

View GitHub Profile
@tejzpr
tejzpr / binary_tree.js
Created February 5, 2018 21:53
Javascript Binary Tree
class Node {
constructor(data) {
this.data = data;
this.left = null;
this.right = null;
this.inorderOut = [];
this.preorderOut = [];
this.postorderOut = [];
}
insert(data) {
@tejzpr
tejzpr / strstr.js
Created February 5, 2018 21:22
Javascript strstr
String.prototype.strstr = function(needle) {
const haystack = this;
if(!needle) return [0];
if(!haystack || needle.length > haystack.length) return [-1];
let i,j;
let positions = [];
for(i=0;i<haystack.length;i++) {
let index = i;
j=0;
// JavaScript (ES6) port of the code at https://gist.github.com/bhelx/778542
// Also handles leading 0's in strings
const BASE = 62;
const UPPERCASE_OFFSET = 55;
const LOWERCASE_OFFSET = 61;
const DIGIT_OFFSET = 48;
class Base62{
constructor() {
//Fastest way to copy a Collection in MongoDB
db.getCollection('OriginalCollection').aggregate([ { $out: "ClonedCollection" } ]);