Skip to content

Instantly share code, notes, and snippets.

View nstawski's full-sized avatar

Nina Stawski nstawski

View GitHub Profile
@nstawski
nstawski / README.md
Last active August 29, 2015 13:57 — forked from milroc/README.md

d3.unconf gist.

@nstawski
nstawski / .block
Last active July 30, 2017 18:17
fresh block
license: mit
border: yes
@nstawski
nstawski / longestIncreasingSubsequence.js
Created April 20, 2019 18:58
Longest increasing subsequence, with basic tests
/**
* @param {number[]} nums
* @return {number}
*/
var lengthOfLIS = function(nums) {
if (!nums || !nums.length) { return 0 }
var increasingSubsequences = [];
var maxSubsequence = {
length: 0,
index: 0
@nstawski
nstawski / graphCycles.js
Created April 20, 2019 19:00
Check if there are any nodes that point back to already visited nodes
var detectGraphCycles = function(graph, rootId) {
if (typeof graph[rootId] === 'undefined') { return false };
var currentNode = graph[rootId];
var visited = {};
var graphHasCycles = false;
while (currentNode && currentNode.next) {
if (typeof currentNode.id !== 'undefined') {
if (visited[currentNode.id] === true) {
currentNode = false;
@nstawski
nstawski / promises.js
Created April 20, 2019 19:02
Simple promise display in the right order
let promises = [];
console.log("Displaying promises as they resolve, without proper order:")
for (let i = 0; i < 10; i++) {
let myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
console.log(i);
resolve(i);
}, Math.floor(Math.random() * 5000));