Skip to content

Instantly share code, notes, and snippets.

Avatar

Nina Stawski nstawski

View GitHub Profile
@nstawski
nstawski / promises.js
Created Apr 20, 2019
Simple promise display in the right order
View promises.js
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));
@nstawski
nstawski / graphCycles.js
Created Apr 20, 2019
Check if there are any nodes that point back to already visited nodes
View graphCycles.js
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 / longestIncreasingSubsequence.js
Created Apr 20, 2019
Longest increasing subsequence, with basic tests
View longestIncreasingSubsequence.js
/**
* @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 / .block
Last active Jul 30, 2017
fresh block
View .block
license: mit
border: yes
You can’t perform that action at this time.