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 subscribe(eventName, callback) { | |
if (!Array.isArray(subscribers[eventName])) { | |
subscribers[eventName] = []; | |
} | |
subscribers[eventName].push(callback); | |
} |
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 publish(eventName, data) { | |
if (!Array.isArray(subscribers[eventName])) { | |
return; | |
} | |
subscribers[eventName].forEach(callback => { | |
if (typeof callback === 'function') { | |
callback(data); | |
} | |
}) | |
} |
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 publishSubscribe() { | |
const subscribers = {}; | |
function subscribe(eventName, callback) { | |
if (!Array.isArray(subscribers[eventName])) { | |
subscribers[eventName] = []; | |
} | |
subscribers[eventName].push(callback); | |
} | |
function publish(eventName, data) { | |
if (!Array.isArray(subscribers[eventName])) { |
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 unsubscribe(eventName) { | |
delete subscribers[eventName]; | |
} |
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 subscribe(eventName, callback) { | |
if (!Array.isArray(subscribers[eventName])) { | |
subscribers[eventName] = [] | |
} | |
subscribers[eventName].push(callback); | |
const index = subscribers[eventName].length - 1; | |
return () => { | |
subscribers[eventName].splice(index, 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
const subscribers = { | |
onUserUpdate: [callbackFunction, anotherCallbackFunction], | |
onUserLogin: [callbackFunction, anotherCallbackFunction] | |
}; |
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 initializeDatabase(database) { | |
switch (database.type) { | |
case 'mysql': | |
database.connectToMySql(); | |
break; | |
case 'postgres': | |
database.connectToPostgres(); | |
break; | |
case 'mongodb': | |
database.connectToMongoDb(); |
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 initializeDatabase(database) { | |
if (typeof database.init !== 'function') { | |
throw 'Engine has no init method'; | |
} | |
database.init(); | |
} | |
const mySqlEngine = { | |
type: 'mysql', |
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
import { Grid, DataGenerator } from '../../build/grid.module.js?449264'; | |
import shared from '../_shared/shared.module.js?449264'; | |
const grid = new Grid({ | |
appendTo: 'container', | |
autoHeight: true, | |
callOnFunctions: true, | |
className: '', | |
columns: [ | |
{ |
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
class AnswerGenerator { | |
combinations = []; | |
combinationNumber = -1; | |
generateCombinations(numOfStatements = 5) { | |
const combinations = []; | |
const numOfPossibleCombinations = 2 ** numOfStatements; | |
for (let i = 0; i < numOfPossibleCombinations; i++) { | |
// for every number, convert it to binary | |
const binary = i.toString(2); // 16 => 10000 |
OlderNewer