Skip to content

Instantly share code, notes, and snippets.

View Gabri3l's full-sized avatar

Gabriele Cimato Gabri3l

View GitHub Profile
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) => {
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 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