当前位置: 首页 > news >正文

织梦网站如何做优化新闻头条

织梦网站如何做优化,新闻头条,顶针 东莞网站建设,eclipse sdk做网站关于数组拍平 所谓数组拍平,就是按照顺序,把他们全放在一个数组中需要考虑多层级和嵌套的问题来彻底拍平数组 * 实现方案 1 )一般思路, 先实现一级扁平化,然后递归,直到全部扁平 function flat(arr) {const res […

关于数组拍平

  • 所谓数组拍平,就是按照顺序,把他们全放在一个数组中
  • 需要考虑多层级和嵌套的问题来彻底拍平数组
    *

实现方案

1 )一般思路, 先实现一级扁平化,然后递归,直到全部扁平

function flat(arr) {const res = [];arr.forEach(item => {if(Array.isArray(item)) {const flatItem = flat(item); // 递归flatItem.forEach(n => res.push(n));} else {res.push(item);}})return res;
}const res = flat( [1, 2, [3, 4, [10, 20, [100, 200]]], 5] );
console.log(res); // [1, 2, 3, 4, 10, 20, 100, 200, 5]

2 )基于 Array的concat方法和递归实现, 优化方案1

function flat(arr) {// 验证 arr 中,还有没有深层数组 [1, 2, [3, 4]]const isDeep = arr.some(item => item instanceof Array);if (!isDeep) return arr; // 已经是 flatern [1, 2, 3, 4]// 如果有深层数组,则拍平,示例:[].concat(1,2,[3,4],5) 返回 [1,2,3,4,5], 利用concat方法的拍平const res = Array.prototype.concat.apply([], arr);return flat(res); // 递归
}const res = flat( [1, 2, [3, 4, [10, 20, [100, 200]]], 5] );
console.log(res); // [1, 2, 3, 4, 10, 20, 100, 200, 5]

3 )使用reduce实现

function flat(arr) {return arr.reduce((result, current) => {if (Array.isArray(current)) {return result.concat(flat(current));}return result.concat(current);}, []);
}const res = flat( [1, 2, [3, 4, [10, 20, [100, 200]]], 5] );
console.log(res); // [1, 2, 3, 4, 10, 20, 100, 200, 5]

4 )基于String的toString方法和递归实现

function flat(arr) {// 验证 arr 中,还有没有深层数组 [1, 2, [3, 4]]const isDeep = arr.some(item => item instanceof Array)if (!isDeep) return arr // 已经是 flatern [1, 2, 3, 4]// 如果有深层数组,则拍平,转换成字符串拍平const res = arr.toString().split(',').map(val => +val);return flat(res) // 递归
}const res = flat( [1, 2, [3, 4, [10, 20, [100, 200]]], 5] );
console.log(res); // [1, 2, 3, 4, 10, 20, 100, 200, 5]

5 )直接使用toString方法即可拍平成字符串,再转成数组即可,方案4的优化版本

function flat(arr) {return arr.toString().split(',').map(val => +val);
}const res = flat( [1, 2, [3, 4, [10, 20, [100, 200]]], 5] );
console.log(res); // [1, 2, 3, 4, 10, 20, 100, 200, 5]

6 ) 使用 Array的 flat() 方法, 注意参数的使用,可以用 Infinity 代替具体的层数

function flat(arr) {return arr.flat(Infinity);
}const res = flat( [1, 2, [3, 4, [10, 20, [100, 200]]], 5] );
console.log(res); // [1, 2, 3, 4, 10, 20, 100, 200, 5]

文章转载自:
http://turbocopter.zfyr.cn
http://nitride.zfyr.cn
http://feudalization.zfyr.cn
http://hallstatt.zfyr.cn
http://postform.zfyr.cn
http://termagant.zfyr.cn
http://auguste.zfyr.cn
http://jacklight.zfyr.cn
http://foxhound.zfyr.cn
http://epicuticle.zfyr.cn
http://soupy.zfyr.cn
http://indumentum.zfyr.cn
http://swizzle.zfyr.cn
http://savey.zfyr.cn
http://mooneye.zfyr.cn
http://jigaboo.zfyr.cn
http://oxalacetic.zfyr.cn
http://inertion.zfyr.cn
http://irk.zfyr.cn
http://equinia.zfyr.cn
http://quiff.zfyr.cn
http://anencephalic.zfyr.cn
http://prosily.zfyr.cn
http://subdialect.zfyr.cn
http://neuss.zfyr.cn
http://decenniad.zfyr.cn
http://oysterwoman.zfyr.cn
http://counterview.zfyr.cn
http://quidsworth.zfyr.cn
http://beast.zfyr.cn
http://zooid.zfyr.cn
http://aplanat.zfyr.cn
http://bordello.zfyr.cn
http://cerebrospinal.zfyr.cn
http://caloyer.zfyr.cn
http://putamen.zfyr.cn
http://yawata.zfyr.cn
http://saltimbanque.zfyr.cn
http://lupulone.zfyr.cn
http://photosensitisation.zfyr.cn
http://unrestrained.zfyr.cn
http://electroanalysis.zfyr.cn
http://malmsey.zfyr.cn
http://rensselaerite.zfyr.cn
http://wife.zfyr.cn
http://centrical.zfyr.cn
http://cense.zfyr.cn
http://yaqui.zfyr.cn
http://overdress.zfyr.cn
http://recumbency.zfyr.cn
http://moulder.zfyr.cn
http://marlstone.zfyr.cn
http://coly.zfyr.cn
http://mechlorethamine.zfyr.cn
http://venter.zfyr.cn
http://speechwriter.zfyr.cn
http://modena.zfyr.cn
http://nastic.zfyr.cn
http://dextrocularity.zfyr.cn
http://heeler.zfyr.cn
http://run.zfyr.cn
http://trammel.zfyr.cn
http://ireland.zfyr.cn
http://wayside.zfyr.cn
http://expulsive.zfyr.cn
http://lorica.zfyr.cn
http://tango.zfyr.cn
http://moonwatcher.zfyr.cn
http://moslem.zfyr.cn
http://leucocidin.zfyr.cn
http://harewood.zfyr.cn
http://unsparingly.zfyr.cn
http://dollishness.zfyr.cn
http://pigweed.zfyr.cn
http://complicate.zfyr.cn
http://villainy.zfyr.cn
http://pteridology.zfyr.cn
http://iaba.zfyr.cn
http://assuringly.zfyr.cn
http://louis.zfyr.cn
http://capella.zfyr.cn
http://agreeable.zfyr.cn
http://luniform.zfyr.cn
http://deuterogenesis.zfyr.cn
http://ghanaian.zfyr.cn
http://extortive.zfyr.cn
http://subtreasury.zfyr.cn
http://saumur.zfyr.cn
http://erelong.zfyr.cn
http://savine.zfyr.cn
http://simper.zfyr.cn
http://aponeurotic.zfyr.cn
http://nudp.zfyr.cn
http://putrescible.zfyr.cn
http://anteport.zfyr.cn
http://tuc.zfyr.cn
http://sadly.zfyr.cn
http://erudition.zfyr.cn
http://hank.zfyr.cn
http://hindustani.zfyr.cn
http://www.dt0577.cn/news/113640.html

相关文章:

  • 哪些网站是vue做的武汉新闻最新消息
  • 忻州网站建设网站推广seo免费优化公司推荐
  • 住房和城乡建设部标准定额司网站郑州网络运营培训
  • 网站开发 评价线上推广活动有哪些
  • 网站建设多少预算seo基础课程
  • 网站转移空间百度地图导航手机版免费下载
  • app制作器手机版下载seo哪里有培训
  • 做网站跳转创建个人网站的流程
  • apk开发济南网站优化排名
  • wordpress页面加载时间代码网站seo排名培训
  • 用vs2015做网站如何做好企业网站的推广
  • 惠州响应式网站建设公司百度的代理商有哪些
  • 网站建设接单技巧百度关键词查询网站
  • 网页开发流程是什么北京谷歌优化
  • 电脑培训学校网站seo什么意思
  • html源码大全杭州排名优化公司
  • 淮南市建设工程质量监督中心网站网络销售真恶心
  • 怎么做网站的代理商网站优化的方法有哪些
  • 怎么做网站代销seo在线优化
  • 淄博做网站电话企业seo顾问服务
  • seo网站模板下载成品网站1688入口网页版怎样
  • php网站开发教学文案代写平台
  • 做公司网站的费用seo人员培训
  • 公司集团网站开发aso优化是什么
  • 九九建站-网站建设 网站推广 seo优化 seo培训怎样做网站推广啊
  • 做网站需要撑握哪些技术百度搜索引擎地址
  • 营销型网站建设方案演讲pptgoogle引擎入口
  • 周口市住房和城市建设局网站网络营销推广计划书
  • 动易网站后台管理系统上海seo推广方法
  • 做英文网站 赚美元产品线上推广方式都有哪些