mPrependAll
mPrependAll
(prepended: array) => (base: array) => base
Prepend the contents of one array ahead of another
Consider prependAll instead.
This is for the uncommon case where mutatingbase
is required.const arr = ['c'] const prependAB = mPrependAll(['a', 'b']) const mutatedArr = prependAB(arr) console.log(mutatedArr === arr) // is true console.log(arr) // is ['a', 'b', 'c']
const arr = ['c'] const prependAB = mPrependAll(['a', 'b']) const mutatedArr = prependAB(arr) console.log(mutatedArr === arr) // is true console.log(arr) // is ['a', 'b', 'c']
const arr = ['c'] const prependAB = mPrependAll(['a', 'b']) const mutatedArr = prependAB(arr) console.log(mutatedArr === arr) // is true console.log(arr) // is ['a', 'b', 'c']
const arr = ['c'] const prependAB = mPrependAll(['a', 'b']) const mutatedArr = prependAB(arr) console.log(mutatedArr === arr) // is true console.log(arr) // is ['a', 'b', 'c']
Sometimes we want to mutate an array by prepending values ahead of it. Below, Sam is next in line for a roller coaster. Mike and Luke bought fast passes and want to join the line. Let's move them ahead of Sam.
const queue = ['sam', 'jen'] const cutInLine = mPrependAll(['mike', 'luke']) cutInLine(queue) console.log(queue) // is ['mike', 'luke', 'sam', 'jen']
const queue = ['sam', 'jen'] const cutInLine = mPrependAll(['mike', 'luke']) cutInLine(queue) console.log(queue) // is ['mike', 'luke', 'sam', 'jen']
const queue = ['sam', 'jen'] const cutInLine = mPrependAll(['mike', 'luke']) cutInLine(queue) console.log(queue) // is ['mike', 'luke', 'sam', 'jen']
const queue = ['sam', 'jen'] const cutInLine = mPrependAll(['mike', 'luke']) cutInLine(queue) console.log(queue) // is ['mike', 'luke', 'sam', 'jen']