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
| /** | |
| * Flattens native JS Array objects. | |
| * Uses the native Array.isArray method, therefore array like objects (e.g Arguments object) need to be converted to Array | |
| * instances for this function to work on them (e.g ...arguments) | |
| * @param {Array} list | |
| * @param {Array} newList - not required for the first call of function | |
| * @return {Array} newList | |
| */ | |
| function flatten(list, newList = []) { | |
| for (var i = 0, length = list.length; i < length; 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 ( $ ) { | |
| var invalidations = [ 'invalidRequiredField', 'invalidInput' ]; | |
| invalidations.invalidRequiredField = function invalidRequiredField(params) { | |
| return params.isRequiredField && !params.value; | |
| }; | |
| invalidations.invalidInput = function invalidInput(params) { | |
| var isRequiredField = params.isRequiredField, |
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 binToDec(n) { | |
| var result = 0; | |
| var s = n.toString(); | |
| var len = s.length - 1; | |
| for (var i = len; i >= 0; i--) { | |
| result += s[i] * Math.pow(2, len-i); | |
| } | |
| return result; | |
| } |
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 |
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
| 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
| 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
| 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 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 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) |