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 shouter(whatToShout) { | |
return `${whatToShout.toUpperCase()}!!!` | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! | |
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 isDivisible(divisee, divisor) { | |
return Number.isInteger(divisee / divisor) | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! | |
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 main() { | |
try { | |
doAllTheThings() | |
} catch(e){ | |
reportError(e) | |
console.dir(e) | |
} | |
} | |
function doAllTheThings() { |
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 accessFirstItem(array) { | |
const myArray = array | |
return myArray[0] | |
} | |
function accessThirdItem(array) { | |
const myArray = array | |
return myArray[2] | |
} |
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 minusLastItem(array) { | |
return array.slice(0, array.length-1) | |
} | |
function copyFirstHalf(array) { | |
return array.slice(0, array.length/2) | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) |
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 average(numbers) { | |
function getSum(total, num){ | |
return (total + num) | |
} | |
return (numbers.reduce(getSum))/numbers.length | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
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
/* Scope is the idea of what can or cannot be seen in your code. Global scope encompasses code | |
that can be seen anywhere in your code, including other files and inside functions. Local scope | |
is code that can be accessed inside the current scope chain level. If you declare a variable inside | |
a function for instance, that variable will not be recognized outside that function. This allows for | |
less buggy code and the reuse of variable names.*/ | |
/* Global variables are to be avoided because they increase the risk of writing buggy code. Functions that | |
rely on global variables can be both indeterminate and has side effects, meaning that the function may not | |
produce the same results given the same input and may also have unintended consequences outside the function | |
itself.*/ |
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 createMyObject() { | |
const myObject = {}; | |
myObject.foo = "bar"; | |
myObject.answerToUniverse = 42; | |
myObject['olly olly'] = 'oxen free' | |
myObject.sayHello = function(){ return "hello"} | |
return myObject | |
} | |
/* From here down, you are not expected to |
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 studentData = [ | |
{ | |
name: 'Tim', | |
status: 'Current student', | |
course: 'Biology', | |
}, | |
{ | |
name: 'Sue', | |
status: 'Withdrawn', | |
course: 'Mathematics', |
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
/* After removing any falsey items from the raw text using the getTokens function, we are left with one clean | |
lower case string containing only words seperated by spaces. The mostFrequentWord function takes that string | |
and assigns it to a variable, words. The function then iterates through each word and if it encounters a new | |
word it adds one to a new key in an object, wordFrequencies. If it has already encountered the word, it adds | |
one to the key at which it first encountered the word. | |
Afterwards, it sets a variable, currentMaxKey, to the first word in the wordFrequencies object and another | |
variable, currentMaxCount, to whatever index of the currentMaxKey in the wordFrequencies object. | |
Next the function iterates over every property in the wordFrequencies object. It then runs an if statement |
OlderNewer