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 makeFunction() { | |
| let myVar = 123 | |
| return function (s) { | |
| console.log(eval(s)) | |
| } | |
| } | |
| const func = makeFunction() |
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
| <!doctype html> | |
| <html lang="en"> | |
| <body> | |
| <script type="hash-module" id="sum"> | |
| export const sum = (a, b) => a + b; | |
| </script> | |
| <!-- All hash modules need to go before this script. --> | |
| <!-- This cant be a type="module", it must be executed immediately. --> | |
| <script> |
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
| export function observePosition(element, callback) { | |
| const trackDiv = document.createElement("div") | |
| Object.assign(trackDiv.style, { | |
| position: "fixed", | |
| pointerEvents: "none", | |
| width: "2px", | |
| height: "2px", | |
| }) | |
| if (element.children.length) { | |
| element.insertBefore(trackDiv, element.firstChild) |
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 arr = [1, 2, 3, 4] | |
| const handler = { | |
| get(target, prop, receiver) { | |
| // try to convert property to a number | |
| const n = +prop | |
| // if it's a number less than zero, return the correct item from the array | |
| if (!isNaN(n) && n<0) { | |
| return Reflect.get(target, target.length + n, receiver) | |
| // otherwise continue as normal with the property |
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
| // pass in 2 letter country code | |
| const getFlagEmoji = countryCode=>String.fromCodePoint(...[...countryCode.toUpperCase()].map(x=>0x1f1a5+x.charCodeAt())) |
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 fib = n => { | |
| const r5 = fib.r5 || (fib.r5=5**.5) | |
| return Math.floor((((1+r5)/2)**n - ((1-r5)/2)**n)/r5) | |
| } |
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 isPalindrome = ([...s]) => ''+s == s.reverse() |
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 fibonacci(n) { | |
| if (n < 0) throw RangeError("Negative arguments not implemented") | |
| return fib(n)[0] | |
| } | |
| function fib(n) { | |
| if (n) { | |
| const [a, b] = fib(~~(n / 2)), | |
| c = a * (b * 2n - a), | |
| d = a * a + b * b |
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
| :nth-child(1) { --nth-child: 1 } | |
| :nth-child(2) { --nth-child: 2 } | |
| :nth-child(3) { --nth-child: 3 } | |
| :nth-child(4) { --nth-child: 4 } | |
| :nth-child(5) { --nth-child: 5 } | |
| /* ... */ | |
| * { | |
| background-color: hsl(calc(100 * var(--nth-child)) 100% 40%); | |
| } |
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 shuffle(array) { | |
| let a = [...array], m = a.length, i | |
| while (m) { | |
| // Pick a remaining element | |
| i = ~~(Math.random() * m--); | |
| // Swap it with the current element | |
| [a[m], a[i]] = [a[i], a[m]] | |
| } | |
| return a | |
| } |
NewerOlder