Splitting strings
When splitting strings, the sequence of characters we split at does not appear in the result. We can get all letters by splitting at the empty string.
Read full articleMath.max()
returns the largest of zero or more numbers passed to it. We can use the spread operator when passing an array to get the largest number from that array.
// get the largest number from a list of numbers
Math.max(69, 420, 108, 47) // ⇒ 420
// passing an array instead of individual numbers returns `NaN`
const numbers = [69, 420, 108, 47]
Math.max(numbers) // ⇒ NaN
// we get the expected result by spreading the array
const numbers = [69, 420, 108, 47]
Math.max(...numbers) // ⇒ 420
// get the largest number from a list of numbers
Math.max(69, 420, 108, 47) // ⇒ 420
// passing an array instead of individual numbers returns `NaN`
const numbers = [69, 420, 108, 47]
Math.max(numbers) // ⇒ NaN
// we get the expected result by spreading the array
const numbers = [69, 420, 108, 47]
Math.max(...numbers) // ⇒ 420
// get the largest number from a list of numbers
Math.max(69, 420, 108, 47) // ⇒ 420
// passing an array instead of individual numbers returns `NaN`
const numbers = [69, 420, 108, 47]
Math.max(numbers) // ⇒ NaN
// we get the expected result by spreading the array
const numbers = [69, 420, 108, 47]
Math.max(...numbers) // ⇒ 420
// get the largest number from a list of numbers
Math.max(69, 420, 108, 47) // ⇒ 420
// passing an array instead of individual numbers returns `NaN`
const numbers = [69, 420, 108, 47]
Math.max(numbers) // ⇒ NaN
// we get the expected result by spreading the array
const numbers = [69, 420, 108, 47]
Math.max(...numbers) // ⇒ 420
The same works for Math.min()
.
// get the smallest number from a list of numbers
Math.min(69, 420, 108, 47) // ⇒ 47
// passing an array instead of individual numbers returns `NaN`
const numbers = [69, 420, 108, 47]
Math.min(numbers) // ⇒ NaN
// we get the expected result by spreading the array
const numbers = [69, 420, 108, 47]
Math.min(...numbers) // ⇒ 47
// get the smallest number from a list of numbers
Math.min(69, 420, 108, 47) // ⇒ 47
// passing an array instead of individual numbers returns `NaN`
const numbers = [69, 420, 108, 47]
Math.min(numbers) // ⇒ NaN
// we get the expected result by spreading the array
const numbers = [69, 420, 108, 47]
Math.min(...numbers) // ⇒ 47
// get the smallest number from a list of numbers
Math.min(69, 420, 108, 47) // ⇒ 47
// passing an array instead of individual numbers returns `NaN`
const numbers = [69, 420, 108, 47]
Math.min(numbers) // ⇒ NaN
// we get the expected result by spreading the array
const numbers = [69, 420, 108, 47]
Math.min(...numbers) // ⇒ 47
// get the smallest number from a list of numbers
Math.min(69, 420, 108, 47) // ⇒ 47
// passing an array instead of individual numbers returns `NaN`
const numbers = [69, 420, 108, 47]
Math.min(numbers) // ⇒ NaN
// we get the expected result by spreading the array
const numbers = [69, 420, 108, 47]
Math.min(...numbers) // ⇒ 47
When splitting strings, the sequence of characters we split at does not appear in the result. We can get all letters by splitting at the empty string.
Read full articleWhen a feature calls for the first five photos from a list and a link that says “27 more photos”, we can split the list into these two blocks.
Read full articleWe can chain many functions together into a single function. That new function takes one input and runs it through its individual functions one by one.
Read full articleWe can create a helper function that makes functions return their Boolean opposite. This can be useful in the shorthand syntax for array methods.
Read full articleWith this helper function, we can map over objects and change each of their values like we would do with arrays.
Read full articleWe can turn arrays of absolute numbers into relative numbers. The largest value becomes 1, with the others calculated based on that largest value.
Read full article