CALLBACKS are a way to make sure certain code doesn’t execute until another code has already finished execution.
Let's check this example:
- function 1:
function study(what){
console.log(`I am studying ${what}.`)
// https://gist.github.com/sandrabosk/d26d441d8e9a5912c6084b0f9e5c2c5d | |
// Goal: display the symbol "!" from every variable | |
const variable1 = [4, 'a', true, '!', 3.14]; | |
console.log(1, variable1[3]); | |
console.log(1, variable1.toString()[9]); | |
const variable2 = { | |
a: '?', |
// updated: 01/24/2020 | |
// https://github.com/ironhack-labs/lab-javascript-functions-and-arrays | |
// *********************************************************************************************** | |
// Iteration #1: Find the maximum | |
// *********************************************************************************************** | |
function maxOfTwoNumbers(num1, num2) { | |
if (num1 > num2) { | |
return num1; |
We will be working on the array of prices
:
const sorted = origArr.slice().sort()
or const sorted1 = [...origArr]
) of the array and then sort the copyThere's plenty of ways to sort arrays in JavaScript (and using .sort()
is probably one of the slowest ones, but it is important to understand it and how it works).
Very often you will see that length - 1
is being used and you might ask yourself why is that.
Here is an example that will demo when and why you should use it and what is the alternative way.
Let's take variable firstName
and has the length 4.
const firstName = "maya";
const someString = "hey there hey what up what" | |
const howMany = (blah) => { | |
let arrOfWords = blah.split(" "); | |
const mappedObj = {}; | |
for(let i=0; i<arrOfWords.length; i++){ | |
if(mappedObj[arrOfWords[i]]){ | |
mappedObj[arrOfWords[i]]++ | |
} else { | |
mappedObj[arrOfWords[i]]=1 |