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 array = [[1,2,[3]],4]; | |
function flatten(arr) { | |
return arr.reduce((newArray, item) => { | |
return [ | |
...newArray, | |
...(Array.isArray(item) ? flatten(item) : [item]) | |
] | |
}, []); | |
} |
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
async function loadNumber() { | |
return fetch(API_URL); | |
} | |
const number = await loadNumber(); | |
// essa linha nao executa enquanto `loadNumber` nao tiver acabado | |
const multiplyRequest = fetch(API_URL, {data: number}); | |
const sumRequest = fetch(API_URL, {data: number}); | |
const promise = Promise.all(multiplyRequest, sumRequest).then((multiply, sum) => { |
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
/* @flow */ | |
import getDocument from 'shared/utils/get-document'; | |
export default function submitGoogleForm(fields, mapper, googleFormId='google-form') { | |
const document = getDocument(); | |
const formData = Object.keys(mapper).reduce((data, key) => { | |
data[mapper[key]] = fields[key]; | |
return 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
let clickStream = Rx.Observable.fromEvent(document.getElementById('link'), 'click'); | |
clickStream | |
.buffer(clickStream.debounce(250)) | |
.map(list => list.length) | |
.filter(x => x === 2) | |
.subscribe(() => { | |
console.log('doubleclick'); | |
}) |
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
let barker = (state) => ({ | |
bark: () => console.log(`woof ${state.name}`) | |
}); | |
let machine = (name) => { | |
let state = { | |
name | |
} | |
return Object.assign({}, |
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
javascript:require(["ns/log"],function(log){log.verbose = true;log.verboseLevel = 0;log.dump();}); |
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
var subscriptions = {}; | |
var Mediator = function() {}; | |
Mediator.prototype.subscribe = function(key, callback, context) { | |
subscriptions[key] = subscriptions[key] || []; | |
subscriptions[key].push({ | |
callback: callback, | |
context: context || window |
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 User(attrs) { | |
for(var name in attrs) { | |
this[name] = attrs[name]; | |
} | |
} | |
User.build = function(attrs) { | |
if(arguments.length === 2) { | |
attrs = { | |
name: arguments[0], |
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
[1,2].forEach(function() { | |
console.log(this); // window | |
}); | |
[1,2].forEach(function() { | |
console.log(this); // {} | |
}.bind({})); |
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 Sale(price) { | |
this.price = price || 100; | |
} | |
Sale.prototype.getPrice = function() { | |
return this.price; | |
}; | |
Sale.prototype.decorate = function(decorator) { | |
var overrides = this.constructor.decorators[decorator], |
NewerOlder