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 delay = ms => new Promise(resolve => setTimeout(resolve, ms)) | |
| delay(500).then(() => console.log(`hello world`)) |
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
| \w*(?<!\/\/)console.log |
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 numberizePixels = (value) => { | |
| return ~~(value.substr(0, (value.length - 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
| const getComputedHeight = (element) => { | |
| return window.getComputedStyle(element).getPropertyValue('height'); | |
| }; |
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 calculatePixelsFromPoints = (pt) => { | |
| var dpi = 96 | |
| return ((pt / 72) * dpi).toFixed(0) | |
| } | |
| let val = 0.5 | |
| console.log(`${val}pt = ${calculatePixelsFromPoints(val)}px`) |
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
| let paragraphs = [].slice.call(document.querySelectorAll('p')) | |
| paragraphs.forEach((paragraph)=>{ | |
| // Do something to each paragraph | |
| }) | |
| // The trick is the [].slice.call() wrapper that is shorthand for accessing the Array.prototype | |
| // https://davidwalsh.name/nodelist-array |
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
| let colophon = (startDate) => { | |
| let now = new Date() | |
| return (startDate < now.getFullYear()) ? startDate += " - " + now.getFullYear() : now.getFullYear() | |
| } | |
| document.querySelector('#colophon').innerText = colophon('2014') |
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 array = [{}, | |
| {}, {}, {}, | |
| {}, {}, {}, | |
| {}, {}, {}, | |
| {}, {} | |
| ] | |
| let columnCount = 4 | |
| let count = 1 |
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
| let random_number = (min, max) => { | |
| return ~~(Math.floor(Math.random() * max) + min) | |
| } | |
| // USAGE | |
| // array[random_number(0, array.length)] | |
| // if (random_number(0, 3) >= 2) { | |
| // // do foo | |
| // } |
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' | |
| let person = [ | |
| { name: "Person 1", age: 28 }, | |
| { name: "Person 2", age: 22 }, | |
| { name: "Person 3", age: 26 } | |
| ] | |
| person.sort(function(obj1, obj2) { | |
| // Ascending: first age less than the previous |
NewerOlder