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
| /* | |
| Case study | |
| Write a function that, when given an object returns the value of a specific property of that object. | |
| Exercise | |
| Create an object with two numeric properties (x=42 and y=666) and log just the x property to the console. | |
| */ | |
| // Procedural style | |
| { |
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 mod = (v, m) => (v + m) % m; | |
| function modulo(m, v) { | |
| return v == null ? (_v) => mod(_v, m) : mod(v, m); | |
| } | |
| console.log('\nJS mod: -1 % 1000 \t=', -1 % 1000); | |
| console.log('\nmod(-1, 1000) \t\t=', mod(-1, 1000)); |
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"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <title>Duplicate Ids</title> | |
| </head> | |
| <body> | |
| <div id="$m1"> | |
| <p id="p1"></p> |
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"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <title>DOM element ref by ($)id</title> | |
| </head> | |
| <body> | |
| <main>Place holder text</main> |
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 presentDateTime(dateObjectOrString) { | |
| const pDateTime = (dateObjectOrString instanceof Date) ? dateObjectOrString : new Date(dateObjectOrString); | |
| const pYear = nonZeroSuppression(pDateTime.getFullYear(), 4); | |
| const pMonth = nonZeroSuppression(pDateTime.getMonth() + 1); | |
| const pDay = nonZeroSuppression(pDateTime.getDate()); | |
| const pHours = nonZeroSuppression(pDateTime.getHours()); | |
| const pMinutes = nonZeroSuppression(pDateTime.getMinutes()); | |
| return `${pYear}-${pMonth}-${pDay}, ${pHours}:${pMinutes}`; | |
| function nonZeroSuppression(num, width = 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 tests = [ | |
| [], | |
| [0], | |
| [0, 0], | |
| [0, 1, 2, 3, 5, 1, 2, 5, 8, 5, 1], | |
| [5, 5, 5, 5], | |
| [5, 5, 5, 8], | |
| [5, 5, 8, 8], | |
| [5, 5, 8, 13], | |
| [5, 8, 8, 8], |
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
| <script> | |
| [][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((!![]+[])[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+!+[]]+(+[![]]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+!+[]]]+(!![]+[])[!+[]+!+[]+!+[]]+(+(!+[]+!+[]+!+[]+[+!+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([]+[])[([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(! |