请将以下代码,采用Pointfree 编程风格改造 export const getChildrenCitys = (cityArr) => { return (codeStr) => { if (!cityArr || cityArr.length < 1) return [] // const start11 = x => y => x.filter(i => ) const start1 = () => { return cityArr.filter((item) => item.code == codeStr)[0]?.children } const start2 = (children) => children.map((item) => item.code) return compose(start2, start1)() } }
时间: 2023-05-22 13:02:36 浏览: 59
const getChildrenCitys = (cityArr) =>
(codeStr) => pipe(
findCity(cityArr, codeStr),
propOr([], 'children'),
map(prop('code'))
);
const findCity = (cityArr, codeStr) =>
cityArr.find((item) => item.code === codeStr);
相关问题
优化下面代码, const getChildrenCitys = (cityArr) => { return (codeStr) => { if (!cityArr || cityArr.length < 1) return [] const fn1 = (x, y) => x.filter(i => i.code == y)[0]?.children; const fn2 = x => x.map(i => i.code) return R.compose(fn2, fn1)(cityArr, codeStr) } } console.log('---', getChildrenCitys(cityArr)("360000"))
const getChildrenCitys = (cityArr) => {
if (!cityArr || cityArr.length < 1) return [];
const fn1 = (x, y) => x.filter(i => i.code === y)[0]?.children;
const fn2 = x => x.map(i => i.code);
return codeStr => fn2(fn1(cityArr, codeStr));
};
console.log('---', getChildrenCitys(cityArr)("360000"));
const login = () => { return{ useStore.userLogin(loginForm); }, }代码有何问题
这段代码有两个问题:
1. `return` 关键字后面的两个花括号应该在同一行,否则会导致语法错误。
2. `useStore.userLogin(loginForm)` 函数调用似乎有问题,可能需要传入一些参数。
下面是修正后的代码:
```
const login = () => {
return useStore.userLogin(loginForm);
}
```
如果 `loginForm` 是一个变量,则需要在调用函数时将其作为参数传递进去。例如:
```
const login = (loginForm) => {
return useStore.userLogin(loginForm);
}
```