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
############################ | |
# USE TYPE AS KEY OF OBJECT# | |
############################ | |
type DayOfTheWeek = "sunday" | "monday" | "tuesday" | "wednesday" | "thursday" | "friday" | "saturday"; | |
type ChoresMap = { [day in DayOfTheWeek]: string }; | |
const chores: ChoresMap = { // ERROR! Property 'saturday' is missing in type '...' | |
"sunday": "do the dishes", | |
"monday": "walk the dog", |
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
/* | |
DISCLAIMER: this snippet is just for educational purposes. Use at your own risk. | |
Instructions: | |
-Step 1: Get a Pluralsight account. | |
-Step 2: Start the first video of a course. | |
-Step 3: paste the following code in the console. | |
Your videos will be downloaded in your current downloads folder. | |
*/ | |
var video = document.querySelector('video'); |
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
Find whole lines not match with word | |
^((?!playerUrl).)*$ | |
Find whole lines match with work | |
^.*\b(one|two|three)\b.*$ | |
Find newline | |
([\n]) | |
Match alphanumeric case insensitive |
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
Online Course Codesmith | |
https://csx.codesmith.io | |
https://www.youtube.com/channel/UCAU_6P-M2VHKePIpu5736ag | |
Great page | |
https://jstherightway.org/#the-good-parts | |
Weird parts of JS | |
http://bonsaiden.github.io/JavaScript-Garden/ |
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 ascending = prices.sort((a, b) => a - b); | |
const descending = prices.sort((a, b) => a + b); | |
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 swap(arr, index1, index2) { | |
if (index1 === index2) throw Error; | |
[arr[index1], arr[index2]] = [arr[index2], arr[index1]]; | |
return arr; | |
} |
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 isInt(n){ | |
return Number(n) === n && n % 1 === 0; | |
} | |
function isFloat(n){ | |
return Number(n) === n && n % 1 !== 0; | |
} |
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* arrayLooper(arr = []) { | |
let i = 0; | |
while (1) { | |
i = i === arr.length ? 0 : i; | |
yield arr[i]; | |
i++; | |
} | |
} |
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 arrayTo2DArray2(list, howMany) { | |
var idx = 0 | |
result = [] | |
while (idx < list.length) { | |
if (idx % howMany === 0) result.push([]) | |
result[result.length - 1].push(list[idx++]) | |
} | |
return result |
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
// Convert int to string: | |
// | OR operator | |
console.log('20' | 0); |