当前位置:网站首页>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)) // 2
Array 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])) // 6
Array 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]]);
边栏推荐
- 永远退出机器学习界!
- 如何通过DBeaver 连接 TDengine?
- 【C语言】剖析函数递归(2)
- Redis全部
- There are several ways to jump to js source code, jump on the current page, jump on the blank page
- Oracle数据库的闪回技术
- scrapy框架初识1
- this的绑定指向详细解答
- To eliminate air bubbles to save the mushroom h5 small game source code
- SQL Server 2019 installation error 0 x80004005 service there is no timely response to the start or control request a detailed solution
猜你喜欢
qt 编译报错 No rule to make target
PHP+MYSQL [Student Information Management System] (Minimalist Edition)
Introduction to Scala Basic Syntax (3) Various Operators in Scala
UAC绕过学习-总结
Automatically generate code generator recommendation-code-gen
嵌入式系统驱动初级【2】——字符设备驱动基础上_基础框架
js秒表倒计时插件
【C语言】剖析函数递归(1)
RISC-V 指令格式和6种基本整数指令
Win11怎么修改关机界面颜色?Win11修改关机界面颜色的方法
随机推荐
js半圆环加载进度动画js特效
Mysql索引详解(图文并茂)
自媒体创作怎样提高原创度,打造爆款作品?
高效代码静态测试工具Klocwork 2022.2——Portal全新升级、支持RLM
第48篇-timestamp2参数分析【2022-08-01】
什么是 commonjs2
Taurus.MVC V3.0.3 microservice open source framework released: Make the evolution of .NET architecture easier in large concurrency.
Interpretation of new features | MySQL 8.0 GIPK invisible primary key
uniapp/小程序 onload方法每次打开页面都执行解读
sql concat() function
单例模式的七种写法,你都知道吗?
js源码跳转的几种方式,在当前页面跳转,在空白页跳转
使用Amazon SageMaker 构建基于自然语言处理的文本摘要应用
js炫酷仪表盘插件
svg balloon rises explosion js special effect
路由-Tab切换页面
FreeRTOS creation tasks - dynamic creation, static creation
工厂方法模式
路由-嵌套路由
图论之Kruskal,最小生成树如何优雅解题?