This file contains hidden or 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
/* | |
Copyright (c) 2021, Ronen Elster | |
Permission to use, copy, modify, and/or distribute this software for any | |
purpose with or without fee is hereby granted, provided that the above | |
copyright notice and this permission notice appear in all copies. | |
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
This file contains hidden or 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 newData(options = {}) { | |
var data = Object.assign({ | |
sort: 'date+', | |
}, options, { queue: [] }) | |
return data; | |
} | |
function delay(timeout = 0) { | |
return new Promise((resolve, reject) => setTimeout(resolve, timeout)); | |
} |
This file contains hidden or 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
header { | |
margin-top: 20px; | |
display: flex; | |
justify-content: space-around; | |
} |
This file contains hidden or 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 binder(instance) { | |
for (var prop in instance) { | |
if (typeof instance[prop] === 'function' && !instance.hasOwnProperty(prop)) { | |
instance[prop] = instance[prop].bind(instance); | |
} | |
} | |
} | |
function binder2(instance, prototype) { | |
Object.keys(prototype) |
This file contains hidden or 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 func() { | |
for (var i = 0; i < 10; i++) { | |
setTimeout(function() { | |
console.log('i:' + i); | |
}, 0); | |
} | |
} | |
// func(); | |
function solution1() { | |
for (let i = 0; i < 10; i++) { |
This file contains hidden or 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 connect(mapStateToProps, mapDispatchToProps) { | |
return function connector(Component) { | |
class ContainerComponent extends React.Component { | |
componentDidMount() { | |
const { store } = this.context; | |
this.unsubscribe = store.subscribe(() => this.forceUpdate()); | |
} | |
componentWillUnmount() { | |
this.unsubscribe(); |
This file contains hidden or 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* gen(param) { | |
if (!Array.isArray(param)) | |
yield param; | |
else | |
for (let item of param) | |
yield* gen(item); | |
} | |
function* genNumbers(iterable) { | |
var items = gen(iterable); |
This file contains hidden or 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
var Modules = new Map(); | |
function addModule(id, searchFn) { | |
if (Modules.has(id)) { | |
throw 'Error: module: ' + id + ' already exists.'; | |
} | |
Modules.set(id, searchFn); | |
} | |
function searchFn(id, query) { |
This file contains hidden or 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
/** | |
* add the result of a function as an argument for the next function, e.g f(g(c)) | |
* @param {...Function} functions to be composed | |
* @return {Function} the composed function | |
*/ | |
function compose() { | |
var funcs = arguments; | |
return function composed(value) { | |
var i = funcs.length; |
This file contains hidden or 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(window){ | |
// sample data from server | |
var data1 = [ { "company_name":"Medline Industries, Inc.", "product":"Benzalkonium Chloride", "price":"481.63" }, { "company_name":"PD-Rx Pharmaceuticals, Inc.", "product":"Alprazolam", "price":"167.62", "fda_date_approved":"02/12/2015" }, { "company_name":"West-ward Pharmaceutical Corp.", "product":"Flumazenil", "fda_date_approved":"23/04/2015" }, { "company_name":"HyVee Inc", "product":"Aspirin", "price":"218.32", "fda_date_approved":"26/07/2015" }, { "company_name":"Aurobindo Pharma Limited", "product":"carisoprodol", "price":"375.58", "fda_date_approved":"28/11/2014" }, { "company_name":"Apotex Corp", "product":"Risperidone", "price":"213.49", "fda_date_approved":"06/11/2015" }, { "company_name":"Unit Dose Services", "product":"Lovastatin", "price":"169.14", "fda_date_approved":"14/09/2015" }, { "company_name":"Jubilant HollisterStier LLC", "product":"Dog Hair Canis spp.", "fda_date_approved":"31/12/2014" }, { "company_name":"AAA Pharmaceutical, Inc |
NewerOlder