pruneStart
pruneStart
(pruneArg: Character | Character[]) => (aString: string) => string
Prune characters off the start of a string
const pruneInitialDashes = pruneStart('-') pruneInitialDashes('--abc--') // is 'abc--'
const pruneInitialDashes = pruneStart('-') pruneInitialDashes('--abc--') // is 'abc--'
const pruneInitialDashes = pruneStart('-') pruneInitialDashes('--abc--') // is 'abc--'
const pruneInitialDashes = pruneStart('-') pruneInitialDashes('--abc--') // is 'abc--'
Sometimes we want to remove characters from the start of strings. Below, we have a price-searching tool that unfortunately gives us raw strings. Let's prune the known characters and turn the prices into numbers. Then we can get the best price.
const rawPricesFound = ['$24.50', '22.99', '• $28.00'] const getPrice = compose([pruneStart([' ', '•', '$']), Number]) const getBestPrice = compose([mapValues(getPrice), getMinValue]) const bestPrice = getBestPrice(rawPricesFound) console.log(bestPrice) // is 22.99
const rawPricesFound = ['$24.50', '22.99', '• $28.00'] const getPrice = compose([pruneStart([' ', '•', '$']), Number]) const getBestPrice = compose([mapValues(getPrice)<string[]>, getMinValue]) const bestPrice = getBestPrice(rawPricesFound) console.log(bestPrice) // is 22.99
const rawPricesFound = [ '$24.50', '22.99', '• $28.00', ] const getPrice = compose([ pruneStart([' ', '•', '$']), Number, ]) const getBestPrice = compose([ mapValues(getPrice), getMinValue, ]) const bestPrice = getBestPrice(rawPricesFound) console.log(bestPrice) // is 22.99
const rawPricesFound = [ '$24.50', '22.99', '• $28.00', ] const getPrice = compose([ pruneStart([' ', '•', '$']), Number, ]) const getBestPrice = compose([ mapValues(getPrice)<string[]>, getMinValue, ]) const bestPrice = getBestPrice(rawPricesFound) console.log(bestPrice) // is 22.99