Flattening nested arrays
We can un-nest arrays with a native function now. We can also define how many levels of nesting we want to take out, to a maximum of “all levels”.
Read full articleBackticks turn strings into “template literals” in JavaScript. They allow you to interpolate variables, the results of calculations, and even the return values of function calls.
const age = 4
// the “old” way to get the value of `age` into a strings
const concatenation = "Little Bobby is " + age + " years old."
// use `${expression}` to do the same in a template literal
const interpolation = `Little Bobby is ${age} years old.`
// an expression can be a calculation
const withCalculation = `Next year, Bobby will be ${age + 1} years old.`
// you can even use the return value of a function call in an expression
const withFunctionCall = `${age} years are ${yearsInDays(age)} days.`
const age = 4
// the “old” way to get the value of `age` into a strings
const concatenation = "Little Bobby is " + age + " years old."
// use `${expression}` to do the same in a template literal
const interpolation = `Little Bobby is ${age} years old.`
// an expression can be a calculation
const withCalculation = `Next year, Bobby will be ${age + 1} years old.`
// you can even use the return value of a function call in an expression
const withFunctionCall = `${age} years are ${yearsInDays(age)} days.`
const age = 4
// the “old” way to get the value of `age` into a strings
const concatenation = "Little Bobby is " + age + " years old."
// use `${expression}` to do the same in a template literal
const interpolation = `Little Bobby is ${age} years old.`
// an expression can be a calculation
const withCalculation = `Next year, Bobby will be ${age + 1} years old.`
// you can even use the return value of a function call in an expression
const withFunctionCall = `${age} years are ${yearsInDays(age)} days.`
const age = 4
// the “old” way to get the value of `age` into a strings
const concatenation = "Little Bobby is " + age + " years old."
// use `${expression}` to do the same in a template literal
const interpolation = `Little Bobby is ${age} years old.`
// an expression can be a calculation
const withCalculation = `Next year, Bobby will be ${age + 1} years old.`
// you can even use the return value of a function call in an expression
const withFunctionCall = `${age} years are ${yearsInDays(age)} days.`
We can un-nest arrays with a native function now. We can also define how many levels of nesting we want to take out, to a maximum of “all levels”.
Read full articleWe’re often extracting properties from an array of objects. With a higher-order function, this becomes more readable and easier to do.
Read full articleWe can split an array in two based on a condition: matches go in the first array, everything else goes in the second.
Read full articleThis neat little trick makes values logged to the console much more readable with a minor adjustment to how we log it.
Read full articleThe default behavior of sorting arrays assumes every value is a string. That leads to unexpected behavior when working with numbers.
Read full articleThis helper function lets us remove all instances of specific values from an array.
Read full article