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
"use strict"; | |
(() => { | |
const root = document.querySelector("#root"); | |
const docFragment = document.createDocumentFragment(); | |
const arraySize = 100; | |
const items = Array.from(Array(arraySize).keys()); | |
const options = { | |
root: null, |
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
// eg (123) 456-7890 | |
formatter(s) { | |
// strip out all formatting that exists on the string | |
const tel = s.replace(/[(\-)\s]/g, ''); | |
// if there is nothing after sanitizing or non-numeric characters | |
// were entered then simply return the current state | |
if (!tel) { | |
return { tel: '' }; | |
} else if (tel.match(/[^.\d]/g)) { | |
return this.state; |
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
typeof 'foo'; // "string" | |
typeof 42; // "number | |
typeof {}; // "object" | |
typeof true; // "boolean" | |
typeof null; // "object" | |
typeof undefined; // "undefined" | |
typeof () => {}; // "function" | |
typeof []; // "object" | |
typeof Symbol(); // "symbol" |
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 person = { kind : ‘person’ }; | |
var shaun = Object.create(person); | |
person.isPrototypeOf(shaun); // true | |
person.kind // 'person' | |
shaun.kind // 'person' | |
shaun.sayHello = function(){ console.log(‘Hello’) }; |
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
JSON.stringify({foo : true, bar : false}); // returns "{"foo":true,"bar":false}" | |
JSON.stringify([1, "false", false]); // returns "[1,"false",false]" note the last false is not surrounded by quotes | |
JSON.stringify({ a: 2 }, null, " "); // returns '{\n "a": 2\n}' | |
JSON.stringify({ a: 2 }, null, 4); // returns '{\n "a": 2\n}' | |
function replacer(k,v) { | |
if( typeof v === "string") return; | |
if( typeof v === "number") return 2*v; | |
return v; |
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
JSON.parse('{"foo" : "true", "bar" : "false"}'); // returns Object { foo : true, bar : false } | |
// returns Object {p: 10} | |
JSON.parse('{"p": 5}', function (k, v) { | |
if(k === "") return v; // if topmost value, return it, | |
return v * 2; // else return v * 2. | |
}); |
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 isBigEnough(element, index, array) { | |
return element >= 10; | |
} | |
var passed = [2, 5, 8, 1, 4].some(isBigEnough); // passed is false | |
passed = [12, 5, 8, 1, 4].some(isBigEnough); // passed is true |
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
// will return 15 | |
[1,2,3,4,5].reduceRight(function(previousValue, currentValue){ | |
return previousValue + currentValue; | |
}); | |
// will return 25 since we passed in the initial value | |
[1,2,3,4,5].reduceRight(function(previousValue, currentValue){ | |
return previousValue + currentValue; | |
}, 10); |
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
// will return 15 | |
[1,2,3,4,5].reduce(function(previousValue, currentValue){ | |
return previousValue + currentValue; | |
}); | |
// will return 25 since we passed in the initial value | |
[1,2,3,4,5].reduce(function(previousValue, currentValue){ | |
return previousValue + currentValue; | |
}, 10); |
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
// iterating through a collection of elements returned by querySelectorAll | |
var elems = document.querySelectorAll('select option:checked'); | |
var values = [].map.call(elems, function(obj) { | |
return obj.value; | |
}); | |
// reverse a string | |
var str = '12345'; | |
[].map.call(str, function(x) { | |
return x; |
NewerOlder