当前位置:网站首页>js array recursively use
js array recursively use
2022-08-02 13:12:00 【Beijing carries the handle】
Fibonacci sequence:
1,1,2,3,5,8,13,21,34...
function fi(n){if(n == 1 || n == 2) return 1;return fi(n-1) + fi(n-2)}console.log(fi(3)) // 2Array sum:
function sum(arr){if(arr.length == 0){return 0}else if(arr.length == 1){return arr[0]}else{return arr[0] + sum(arr.slice(1))// slice(1) intercepts the data from the first to the end of the array}}console.log(sum([1,2,3])) // 6Array flattening:
const res = [];const fn = arr => {for (let i = 0; i < arr.length; i++) {if (Array.isArray(arr[i])) {fn(arr[i]);} else {res.push(arr[i]);}}}fn([1,[2,3]]);边栏推荐
猜你喜欢
随机推荐
Taurus.MVC V3.0.3 微服务开源框架发布:让.NET 架构在大并发的演进过程更简单。
RISC-V instruction format and 6 basic integer instructions
Taurus.MVC V3.0.3 microservice open source framework released: Make the evolution of .NET architecture easier in large concurrency.
图论之Floyd,多源图最短路如何暴力美学?
图神经网络(GNN)的简介「建议收藏」
String concatenation in SQL
JS中的闭包
js炫酷仪表盘插件
Set proxy server (Google+IE) "Recommended Collection"
.Net 5.0 Quick Start Redis
There are several ways to jump to js source code, jump on the current page, jump on the blank page
工厂方法模式
图文短视频自媒体怎么创作?如何让点击量达到10W?
Automatically generate code generator recommendation-code-gen
Redis all
嵌入式系统驱动初级【2】——字符设备驱动基础上_基础框架
网络流详解(流网图一般能够反映什么信息)
js数组递归使用
LeetCode_377_组合总和Ⅳ
FreeRTOS实验--删除任务



![PHP+MYSQL [Student Information Management System] (Minimalist Edition)](/img/86/d5d39eef0600acabbf3ac16c255c18.png)





