将 jquery 函数转换为函数式编程函数 [英] Transforming jquery function into functional programming function
本文介绍了将 jquery 函数转换为函数式编程函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是函数式编程的初学者,并且我想用函数式编程范式改造这个jquery函数.
I'm a beginner in functional programming and I want to transform this jquery function with the functional programming paradigm.
我尝试转换这个函数
merge: function( first, second ) {
var len = +second.length,
j = 0,
i = first.length;
for ( ; j < len; j++ ) {
first[ i++ ] = second[ j ];
}
first.length = i;
return first;
}
它只是一个简单的合并函数.
例如,当我调用
It is just a simple merge function.
For example, when I call
merge([0,1,2,3,4],[5,6,7,8,9]);
它产生
[0,1,2,3,4,5,6,7,8,9]
我所做的是
merge: function( first, second ){
var len = +second.length,
j = 0,
i = first.length;
let modify = x =>{
let merging =
j => {
first[ i++ ] = second[ j ];
};
R.map(merging, R.range(0,len))
return first;
}
modify
}
但它不起作用.
我知道我的代码有问题,但我猜不出它在哪里......
But it does not work.
I know something is wrong in my code but I cannot guess where is it...
推荐答案
您也可以简单地使用 ES6 将它们解构成一个新的:
You can also simply destructure them with ES6 into a new one:
console.log([...[0,1,2,3,4], ...[5,6,7,8,9]])
// OR if you really want a pure function
let mergeArrays = (a,b) => [...a, ...b]
console.log(mergeArrays([0,1,2,3,4], [5,6,7,8,9]))
这篇关于将 jquery 函数转换为函数式编程函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文