Skip to content

Instantly share code, notes, and snippets.

View indreklasn's full-sized avatar
👋

Trevor I. Lasn indreklasn

👋
View GitHub Profile
yarn add react react-dom && yarn start
function sayName(name) {
return name
}
sayName('Indrek Lasn') // 'Indrek Lasn'
const add = (a, b, ...rest) => {
console.log(rest); // [3, 4, 5]
console.log(...rest) // 3, 4, 5
};
add(1, 2, 3, 4, 5);
const add = (a, b, ...[c, d, e]) => {
console.log(c) // 3
console.log(d) // 4
console.log(e) // 5
return a + b + c + d + e
};
add(1, 2, 3, 4, 5); // 15
const add = (a, b, ...rest, c) => {
const allOtherNumbers = rest.reduce((number, acc) => number += acc)
const sum = a + b + c + allOtherNumbers
return sum
}
add(1, 2, 3, 4, 5, 6, 7, 8, 9)
const add = (a, b, ...rest, c) => {
const allOtherNumbers = rest.reduce((number, acc) => number += acc)
const sum = a + b + c + allOtherNumbers
return sum
}
add(1, 2, 3, 4, 5, 6, 7, 8, 9)
const add = (a, b, c, ...rest) => {
const allOtherNumbers = rest.reduce((number, acc) => number += acc)
const sum = a + b + c + allOtherNumbers
return sum
}
add(1, 2, 3, 4, 5, 6, 7, 8, 9) // 45 in this case
const add = (a, b, c, ...rest) => {
const allOtherNumbers = rest.reduce((number, acc) => number += acc)
const sum = a + b + c + allOtherNumbers
return sum
}
add(1, 2, 3, 4, 5, 6, 7, 8, 9) // 45 in this case
const add = (a, b, c, ...rest) => {
const allOtherNumbers = rest.reduce((number, acc) => number += acc)
const sum = a + b + c + allOtherNumbers
return sum
}
add(1, 2, 3, 4, 5, 6) // 21 in this case
const add = (a, b, c, ...rest) => {
console.log(rest) // [4, 5, 6]
return a + b + c
}
add(1, 2, 3, 4, 5, 6) // still 6