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
const range = (first, last) => { | |
const firstValue = last ? first : 1; | |
const length = last ? last - first + 1 : first; | |
return Array.from({ length }) | |
.map((_, i) => i + firstValue); | |
} |
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
const mockNode = { | |
get firstChild() { | |
return undefined; | |
} | |
}; | |
const stubFirstChildGetter = sinon.stub().returns(false).onFirstCall().returns(true); | |
sinon.stub(mockNode, 'firstChild') | |
.get(stubFirstChildGetter); |
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
class MyComponent extends React.Component { | |
partialHandleLinkClick(type, activeType){ | |
return function(e) { | |
const hasKeyboardModifier = e.ctrlKey || e.shiftKey || e.altKey || e.metaKey; | |
updateType(type, activeType, hasKeyboardModifier); | |
}; | |
} | |
render() { | |
const types = [ 'Foo', 'Bar', 'Baz' ]; | |
return ( |
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
{ | |
"name": "library-js", | |
"version": "1.0.0", | |
"description": "Starter for library development with ES6, Babel, Mocha and npm scripts", | |
"main": "./dist/index.js", | |
"scripts": { | |
"start": "npm run dev", | |
"dev": "npm test -- -w", | |
"init": "mkdir dist", | |
"clean": "rm -rf dist", |
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 map = ([ head, ... tail ], fn) => | |
( (head !== undefined && tail.length) ? ( tail.length ? [ fn(head), ...(map(tail, fn)) ] : [ fn(head) ] ) : []); |
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 map(arr, fn) { | |
var head = arr[0]; | |
var tail = arr.slice(1); | |
if(head === undefined && tail.length === 0) return []; | |
if(tail.length === 0) { | |
return [ fn(head) ]; | |
} | |
return [].concat(fn(head), map(tail, fn)); | |
} |
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
{ | |
"name": "frontend-starter", | |
"version": "1.0.0", | |
"description": "React, browserify and babel. With npm scripts and browser-sync", | |
"main": "index.js", | |
"config": { | |
"ut": "{,!(node_modules)/**/}*.test.js" | |
}, | |
"scripts": { | |
"start": "npm run dev", |
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 join([ head, ...tail ], separator = ',') { | |
if (head === undefined && !tail.length) return ''; | |
return tail.length ? head + separator + join(tail, separator) : head; | |
} |
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 reduce([ head, ...tail ], fn, initial) { | |
if(head === undefined && tail.length === 0) return initial; | |
if(!initial) { | |
const [ newHead, ...newTail] = tail; | |
return reduce(newTail, fn, fn(head, newHead)); | |
} | |
return tail.length ? reduce(tail, fn, fn(initial, head)) : [ fn(initial, head) ]; | |
} |
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 filter([ head, ...tail ], fn) { | |
const newHead = fn(head) ? [ head ] : []; | |
return tail.length ? [ ...newHead, ...(filter(tail, fn)) ] : newHead; | |
} |