当前位置:网站首页>Brainstorming -- using reduce method to reconstruct concat function
Brainstorming -- using reduce method to reconstruct concat function
2022-07-24 22:24:00 【Brave * Niuniu】
utilize reduce Method refactoring concat function
Array.prototype.myconcat = function () {
var res = this;
var a = Array.prototype.slice.apply(arguments)
return a.reduce(function(p,e){
//*****************************************
if(Array.isArray(e)){
var x = e.reduce(function(v,t){
v.push(t)
return v
},p)
return x
}else{
p.push(e)
return p
}
//*******************************************
},res)
}
var i = [1, 2, 3, 4]
console.log(i.myconcat([34, 5, 6], 78, [25, 34],[23,76,[1,2,3]]));
//[1, 2, 3, 4, 34, 5, 6, 78, 25, 34, 23, 76, Array(3)]
a = [1,2,3]
b = [4,5,6]
var x = a.reduce(function(v,t){
// You can't go back here return v.push(t)
v.push(t)
return v
},b)
console.log(x);
//
边栏推荐
- 实现redis哨兵,模拟master故障场景
- Plane regularization of PCL point cloud processing (55)
- [postgraduate entrance examination vocabulary training camp] day 12 - native, separate, figure, contribution, categories, assessment, propose
- 在机器人行业的专业人士眼里,机器人行业目前的情况如何?
- ACL 2022 | comparative learning based on optimal transmission to achieve interpretable semantic text similarity
- 10 key points and 5 measures for good project management
- "Fundamentals of program design" Chapter 10 function and program structure 7-3 recursive realization of reverse order output integer (15 points)
- 【云原生之kubernetes】kubernetes集群高级资源对象statefulesets
- 线段树,,
- 有序表之AVL树
猜你喜欢

一键编译安装redis6.2.4

Integrated swagger learning

AC automata

实现redis哨兵,模拟master故障场景

第二十周作业

【ICML2022】气候变化与机器学习:机遇、挑战与考虑,121页ppt
![Cell special issue | application and future prediction of AI in protein structure, precision medicine, antibody therapy [review]](/img/2e/7f3cbae33c8a994b38e3bf4f9f13cb.png)
Cell special issue | application and future prediction of AI in protein structure, precision medicine, antibody therapy [review]

How to adjust the default output of vscode to the debugging console to the terminal and the problem of garbled code in both

【数据库学习】Redis 解析器&&单线程&&模型

Go+语言
随机推荐
ASP.NET Core 6.0 基于模型验证的数据验证
ACL 2022 | comparative learning based on optimal transmission to achieve interpretable semantic text similarity
Deep understanding of affairs
Low code that democratizes software development
DDoS attack classification
CAD text styles
Using FRP to achieve intranet penetration
大咖对话:品牌扎堆数藏赛道,下半场的机遇、挑战在哪里?
[postgraduate entrance examination vocabulary training camp] day 12 - native, separate, figure, contribution, categories, assessment, propose
Segment tree,,
通讯异常判断之通讯心跳信号应用编程
AC automata
实现redis哨兵,模拟master故障场景
Time series data in industrial Internet of things
Gradle learning set integration
窗口内最大值或最小值的更新结构——窗口内最大值
General syntax and classification of SQL language (II)
头脑风暴之——利用reduce方法重构concat函数
How about Minsheng futures? Is it safe?
在机器人行业的专业人士眼里,机器人行业目前的情况如何?