我正在寻找可以在 javascript 中编写如下函数的名称:
function imlookingforyourname( list, f ){
return list.reduce(
({left,right},x) => {
if ( f( x ) ){
left.push( x )
} else {
right.push( x )
}
return {left,right}
},{left:[],right:[]}
)
所以
imlookingforyourname( [1,2,3,4,5,6,7,8,9], x => x < 6 )
会回来
{ left: [ 1, 2, 3, 4, 5 ], right: [ 6, 7, 8, 9 ] }
最佳答案
通常,您会得到一个包含两个数组的数组。它是一个分区函数。例如来自
关于javascript - 给定数组和测试函数返回两个数组的函数是否有名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56907965/