当前位置:网站首页>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);
//
边栏推荐
- Gradle learning - getting started with gradle
- 第二十周作业
- 对萌新小白电脑运行速度变慢解决的方法get!٩( ‘ω‘ )و get!٩( ‘ω‘ )و
- 窗口内最大值或最小值的更新结构——窗口内最大值
- 【数据库学习】Redis 解析器&&单线程&&模型
- Implementation of graph structure, from point to edge and then to graph
- ICML2022 | 图神经网络的局域数据增强方法
- 有序表之AVL树
- [icml2022] climate change and machine learning: opportunities, challenges and considerations, 121 ppt
- [cloud native] Devops (IV): integrated sonar Qube
猜你喜欢

Projection regularization of line point set in PCL point cloud processing (56)

AC自动机

从暴力递归到动态规划,记忆化搜索

CAD copy commands
![[which is better to use, apopost or apifox? Just read this!]](/img/58/4dfe5c56d12e8e88b0a7f3583ff0a4.jpg)
[which is better to use, apopost or apifox? Just read this!]

Integrated swagger learning

Gradle learning set integration
![[postgraduate entrance examination vocabulary training camp] day 12 - native, separate, figure, contribution, categories, assessment, propose](/img/6e/97e9335b7017e6e40d248252493e80.png)
[postgraduate entrance examination vocabulary training camp] day 12 - native, separate, figure, contribution, categories, assessment, propose

Im instant messaging develops ten million level concurrent long connection Gateway Technology

由斐波那契数列引述到矩阵快速幂技巧
随机推荐
PCL点云处理之ply文件读取与保存(五十四)
What are the methods of knowledge map relation extraction
Function default parameter pit avoidance Guide
Kubernetes scheduling concept and workflow
Segment tree,,
Gee - dataset introduction mcd12q1
Use kettle to read the data in Excel file and store it in MySQL
[icml2022] climate change and machine learning: opportunities, challenges and considerations, 121 ppt
PCL点云处理之CSF布料模拟滤波(五十九)
单调栈结构练习——子数组最小值的累加和
Leetcode 102. sequence traversal of binary tree
From violent recursion to dynamic programming, memory search
C # use SQLite
Gradle learning set integration
Gradle 学习 ----Gradle 入门
CSF cloth simulation filtering for PCL point cloud processing (59)
VScode默认输出到调试控制台如何调整到终端以及两者中的乱码问题
CAD text styles
AC自动机
QT learning vs creating QT items shows instances where object references are not set to objects