This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Primes(){ | |
let primeNumbers = [2]; | |
const first = (n) => { | |
if (primeNumbers.length >= n) return primeNumbers.slice(0, n + 1); | |
let value = primeNumbers[primeNumbers.length - 1] + 1; | |
let isPrime; | |
while (primeNumbers.length < n) { | |
isPrime = true; | |
primeNumbers.some((prime) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Event() { | |
let subscribers = []; | |
const subscribe = (...values) => { | |
values.forEach((s) => { | |
if (typeof s === 'function') subscribers.push(s); | |
}); | |
}; | |
const unsubscribe = (...values) => { | |
values.forEach((v) => { | |
if (subscribers.lastIndexOf(v) > -1) subscribers.splice(subscribers.lastIndexOf(v),1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This gist is to show a differnet approach on the merging task. Some | |
conditions might be missing but I just wanted to present a different | |
implementation, adding or editing a constraint is pretty straighforward. | |
*/ | |
'use strict'; | |
const constraint = (passingCondition, consequence) => ({ | |
passed: passingCondition, | |
applyConsequence: consequence |
NewerOlder