mFillRangeWith
mFillRangeWith
(value: any, range: Range) => (anArray: array) => anArray
Fill an array range with
value
Ranges in Common FP are inclusive
Consider fillRange instead.
This is for the uncommon case where mutatinganArray
is required.const range = { startIdx: 1, endIdx: 2 } const zeroOutRange = mFillRangeWith(0, range) const arr = [1, 2, 3, 4] const mutatedArr = zeroOutRange(arr) console.log(mutatedArr === arr) // is true console.log(arr) // is [1, 0, 0, 4]
const range = { startIdx: 1, endIdx: 2 } const zeroOutRange = mFillRangeWith(0, range) const arr = [1, 2, 3, 4] const mutatedArr = zeroOutRange(arr) console.log(mutatedArr === arr) // is true console.log(arr) // is [1, 0, 0, 4]
const range = { startIdx: 1, endIdx: 2 } const zeroOutRange = mFillRangeWith(0, range) const arr = [1, 2, 3, 4] const mutatedArr = zeroOutRange(arr) console.log(mutatedArr === arr) // is true console.log(arr) // is [1, 0, 0, 4]
const range = { startIdx: 1, endIdx: 2 } const zeroOutRange = mFillRangeWith(0, range) const arr = [1, 2, 3, 4] const mutatedArr = zeroOutRange(arr) console.log(mutatedArr === arr) // is true console.log(arr) // is [1, 0, 0, 4]
Sometimes we want to set an array range to a value. Below, we had an issue at our soup factory. No salt was added from 3pm to 5. Now we have to throw away all that soup! Let's reset the hourly numbers to zero.
const cansProducedHourly = [2984, 3012, 3007, 2995, 3001, 3009] const hours3Thru5 = { startIdx: 2, endIdx: 4 } const clearBadCans = mFillRangeWith(0, hours3Thru5) clearBadCans(cansProducedHourly) console.log(cansProducedHourly) // is [2984, 3012, 0, 0, 0, 3009]
const cansProducedHourly = [2984, 3012, 3007, 2995, 3001, 3009] const hours3Thru5 = { startIdx: 2, endIdx: 4 } const clearBadCans = mFillRangeWith(0, hours3Thru5) clearBadCans(cansProducedHourly) console.log(cansProducedHourly) // is [2984, 3012, 0, 0, 0, 3009]
const cansProducedHourly = [ 2984, 3012, 3007, 2995, 3001, 3009, ] const hours3Thru5 = { startIdx: 2, endIdx: 4 } const clearBadCans = mFillRangeWith( 0, hours3Thru5 ) clearBadCans(cansProducedHourly) console.log(cansProducedHourly) // is [2984, 3012, 0, 0, 0, 3009]
const cansProducedHourly = [ 2984, 3012, 3007, 2995, 3001, 3009, ] const hours3Thru5 = { startIdx: 2, endIdx: 4 } const clearBadCans = mFillRangeWith( 0, hours3Thru5 ) clearBadCans(cansProducedHourly) console.log(cansProducedHourly) // is [2984, 3012, 0, 0, 0, 3009]