当前位置:网站首页>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]]);边栏推荐
- GCC版本升级到指定版本
- Taurus.MVC V3.0.3 微服务开源框架发布:让.NET 架构在大并发的演进过程更简单。
- svg balloon rises explosion js special effect
- How to implement waterfall flow layout (what is waterfall flow layout)
- ThinkPHP 5.1反序列化分析和poc
- RestTemplate use: set request header, request body
- php - the first of three solid foundations
- 你知道图论的Dijkstra吗?
- FreeRTOS--stack experiment
- Singleton pattern of seven kinds of writing, you know?
猜你喜欢

Win11怎么修改关机界面颜色?Win11修改关机界面颜色的方法

SQL Server 2014 installation tutorial (nanny-level graphic tutorial)

嵌入式系统驱动初级【2】——字符设备驱动基础上_基础框架

节省50%成本!京东云重磅发布新一代混合CDN产品
![PHP+MYSQL [Student Information Management System] (Minimalist Edition)](/img/86/d5d39eef0600acabbf3ac16c255c18.png)
PHP+MYSQL [Student Information Management System] (Minimalist Edition)

鲁大师7月新机性能/流畅榜:性能跑分突破123万!

LeetCode_377_组合总和Ⅳ

svg气球升起爆炸js特效

WeChat applet getPhoneNumber interface code=40013

吾爱第三课-修改版权和资源
随机推荐
Oracle数据库的闪回技术
Singleton pattern of seven kinds of writing, you know?
Redis全部
selenium chrome driver运行时的cannot determine loading status from target frame detached问题
.Net 5.0快速上手 Redis
麻烦问一下,对mysql 场景注入故障,是不是不是对mysql server 端注入故障,只是对ja
The uniapp/applet onload method executes the interpretation every time the page is opened
pytorch模型转tensorflow模型
【C语言】函数哪些事儿,你真的get到了吗?(2)
Seata分布式事务
【typescript】使用antd中RangePicker组件实现时间限制 当前时间的前一年(365天)
SQL Server 2019 installation error 0 x80004005 service there is no timely response to the start or control request a detailed solution
LeetCode_139_单词拆分
工厂方法模式
Js scratchable latex style draw plug-in
PGSQL database to realize the import and export
Basic operations of openGauss database (super detailed)
FreeRTOS--优先级实验
GCC版本升级到指定版本
如何通过DBeaver 连接 TDengine?