将compose与多个函数一起使用,并将内部函数与param一起使用

我有以下内容:

arrayOfObjects.map((arrayItem,index) => {
  let key = "place_" + (index + 1);                      // generate the key to access an object from 'countrydata'. If we are at the first object (index == 0),the key will be "place_1"
  return (
    <div>
      <img src={countrydata[key].image_location}/>       // access the matching object from 'countrydata' and use it
      <span>{arrayItem.name}</span>                      // access the current array item from 'arrayOfObjects'
    </div>
  );
})

调用所有这些函数并为extractArrVals函数使用第二个参数的最佳方法是什么(请参见我的示例),以便可以使用https://www.30secondsofcode.org/snippet/compose

smily_lydia 回答:将compose与多个函数一起使用,并将内部函数与param一起使用

const compose = (...fns) => fns.reduce((f,g) => (...args) => f(g(...args)));

const extractArrVals = (obj,key) => {
  /////YOUR FUNCTION
};

const dedupe = (data) => {
  /////YOUR FUNCTION
}

const filterOutNonUsable = (data) => {
  /////YOUR FUNCTION
}

// transformer or whatever it's name
const transformer = compose(
  filterOutNonUsable,dedupe,extractArrVals
);

transformer(data.locks.entries,'reseller')
本文链接:https://www.f2er.com/3128832.html

大家都在问