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 signed zero example. | |
// Note that +0 equals -0 in JavaScript. | |
var getPlusZero = () => +0; | |
var getNegativeZero = () => -0; | |
var isPlusZero = x => Math.atan2(0, x) === 0; | |
var isNegativeZero = x => Math.atan2(0, x) !== 0; | |
console.log(isPlusZero(getPlusZero())); | |
console.log(isPlusZero(getNegativeZero())); |
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
Array.prototype.squeeze = function (n, fn) { | |
const from = Object(this).slice(); | |
const to = []; | |
while (n > 0 && from.length) | |
to.push(fn.apply(undefined, from.splice(0, n))); | |
return to; | |
} |
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 _ = require("lodash"); | |
var performRoles = require("./performRoles.js"); | |
performRoles({ foo: 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 updated = (source, property, value) => { | |
const out = {}; | |
Object.keys(source).forEach(key => { | |
out[key] = source[key]; | |
}); | |
out[property] = value; | |
return out; | |
}; | |
const removed = (source, property) => { |
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 _ = new Proxy({}, { get: (target, prop) => it => it[prop] }); | |
// Evaluates to [{ foo: true }] | |
[{ foo: true }, { foo: false }].filter(_.foo); |
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
// Calls 'f' if the parameters are different from the last call. | |
// NOTE: Implement 'notEqual' yourself | |
const changed = f => { | |
let lastParams = undefined, flag = false; | |
return (...args) => { | |
if (!flag || notEqual(lastParams, args)) { | |
f(args); | |
lastParams = args; | |
flag = true | |
} |
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 f(p) { | |
console.log(Date.now()); | |
var x = []; | |
while(x.length < 1000000) x.push(x.length); | |
p = p || {}; | |
setTimeout(function() { | |
f(p); | |
}, 25); | |
}; |
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 randomID() { | |
return Math.random(); | |
} | |
function serialize(obj, store) { | |
const retVal = {}; | |
store = store || { | |
root: retVal, | |
objects: {}, |
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
// copied from https://gist.github.com/lauripiispanen/1fd1c3319084f9913f2d | |
// improved formatting | |
const constrain = ({ | |
pre = () => {}, | |
post = () => {} | |
}) => fn => (...args) => { | |
const throwIf = x => y => { | |
if (x(y)) { | |
throw x(y); | |
} else { |
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
<link rel="import" href="../polymer/polymer.html"> | |
<dom-module id="hello-world"> | |
<template> | |
<h1>Hello</h1> | |
</template> | |
</dom-module> | |
<script type="module"> | |
import { assign } from "./lib/lodash/lodash.js"; |
OlderNewer