Skip to content

Instantly share code, notes, and snippets.

@peyo
peyo / gist:37ece27457945a6bada4a7b890fdc00a
Created October 19, 2019 23:01
Using template strings to uppercase variables in a function.
function shouter(whatToShout) {
return `${whatToShout}`.toUpperCase() + "!!!";
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
@peyo
peyo / gist:ef6cd08a4b5fecb77201dcd2f320482f
Created October 19, 2019 23:15
Lower casing variable and trimming space before and after.
function textNormalizer(text) {
return `${text}`.toLowerCase().trim();
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
function computeArea(width, height) {
return width * height;
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
function celsToFahr(celsTemp) {
return celsTemp * 9 / 5 + 32;
}
function fahrToCels(fahrTemp) {
return (fahrTemp - 32) * 5 / 9;
}
/* From here down, you are not expected to
understand.... for now :)
function isDivisible(divisee, divisor) {
return divisee % divisor === 0
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
function main() {
try {
doAllTheThings();
}
catch(e) {
console.error(e);
reportError(e);
}
}
@peyo
peyo / gist:309be378d80975810e09d887ca87b64e
Created October 28, 2019 05:14
Creating arrays drill
/* Repl.it link: https://repl.it/@PeterYoon/Creating-arrays-drill */
function makeList(item1, item2, item3) {
return [item1, item2, item3];
}
/* From here down, you are not expected to
understand.... for now :)
/* https://repl.it/@PeterYoon/Adding-array-items-drills */
function addToList(list, item) {
list.push(item);
return list;
}
/* From here down, you are not expected to
understand.... for now :)
@peyo
peyo / gist:7f433f9a30ffa3fca28cc1d2bdf28c61
Created October 28, 2019 06:00
Accessing array items (indexer)
/* repl: https://repl.it/@PeterYoon/Accessing-array-items-drill */
/* stackoverflow: https://stackoverflow.com/questions/8238456/how-to-get-value-at-a-specific-index-of-array-in-javascript */
function accessFirstItem(array) {
return array[0];
}
function accessThirdItem(array) {
return array[2];
}
@peyo
peyo / gist:366b25f2d5946f3f9063cd4fbb248ad1
Created October 28, 2019 06:00
accessing array items (indexer)
/* repl: https://repl.it/@PeterYoon/Accessing-array-items-drill */
/* stackoverflow: https://stackoverflow.com/questions/8238456/how-to-get-value-at-a-specific-index-of-array-in-javascript */
function accessFirstItem(array) {
return array[0];
}
function accessThirdItem(array) {
return array[2];
}