Skip to content

Instantly share code, notes, and snippets.

View spiterman's full-sized avatar
🏠
Working from home

Sergey Piterman spiterman

🏠
Working from home
View GitHub Profile
function minimumWindowSubstring(str, substr) {
let lettersSeen = {};
let lettersNeeded = {};
let lettersMissing = 0;
for(let i = 0; i < substr.length; i++) {
if(substr[i] in lettersNeeded){
lettersNeeded[substr[i]] += 1;
} else {
lettersNeeded[substr[i]] = 1;
@spiterman
spiterman / GeneticAlgorithm.js
Created September 27, 2018 02:28
Genetic Algorithm v.2.0
class Organism {
constructor(r, g, b) {
this.r = r;
this.g = g;
this.b = b;
this.mutationSize = 20; //Must be greater than 2
}
reproduce() {
// Prevents negative numbers from appearing
let newR = Math.max(this.r + this.mutateTrait(), 0);
class Organism {
constructor(r, g, b) {
this.r = r;
this.g = g;
this.b = b;
this.mutationSize = 20; //Must be greater than 2
}
reproduce() {
// Prevents negative numbers from appearing
let newR = Math.max(this.r + this.mutateTrait(), 0);
class Environment {
constructor(r, g, b, startingOrganisms) {
this.r = r;
this.g = g;
this.b = b;
this.organisms = [];
this.weaknesses = [];
this.startingOrganisms = startingOrganisms;
this.addOrganisms(this.startingOrganisms);
this.generationTime = 1
class Organism {
constructor(r, g, b) {
this.r = r;
this.g = g;
this.b = b;
this.mutationSize = 10; //Must be greater than 2
}
reproduce() {
// Prevents negative numbers from appearing
let newR = Math.max(this.r + this.mutateTrait(), 0);
@spiterman
spiterman / functionTrees.js
Created August 17, 2018 23:38
Functional Programming Applied to a Binary Search Tree
class TreeNode {
constructor(val) {
this.val = val;
this.left = null;
this.right = null;
}
}
class BST {
constructor() {