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

网站开发流程任务优化网站收费标准

网站开发流程任务,优化网站收费标准,百度怎么对网站处罚,网络工作室起名大全免费取名说在前面 🎈lodash的_.groupBy函数可以将一个数组按照给定的函数分组,返回一个新对象。该函数接收两个参数:第一个参数是要进行分组的数组,第二个参数是用于分组的函数。该函数会对数组中的每个元素进行处理,返回一个值…

说在前面

🎈lodash的_.groupBy函数可以将一个数组按照给定的函数分组,返回一个新对象。该函数接收两个参数:第一个参数是要进行分组的数组,第二个参数是用于分组的函数。该函数会对数组中的每个元素进行处理,返回一个值作为分组依据。最终返回的对象中,每个键代表一组,对应的值则是符合该组的元素组成的数组。

.groupBy函数的主要作用是方便对数组中的元素进行分类或分组,并且在分组后可以方便地对每个组内的元素进行处理,比如统计数量、求平均值等。同时,由于lodash库已经封装了大量的常用函数,使用.groupBy函数也能够减少我们自己编写代码的工作量,提高开发效率。

目标

编写一段可应用于所有数组的代码,使任何数组调用 array. groupBy(fn) 方法时,它返回对该数组 分组后 的结果。

数组 分组 是一个对象,其中的每个键都是 fn(arr[i]) 的输出的一个数组,该数组中含有原数组中具有该键的所有项。

提供的回调函数 fn 将接受数组中的项并返回一个字符串类型的键。

每个值列表的顺序应该与元素在数组中出现的顺序相同。任何顺序的键都是可以接受的。

示例 1:

输入:
array = [{"id":"1"},{"id":"1"},{"id":"2"}
], 
fn = function (item) { return item.id; 
}
输出:
{ "1": [{"id": "1"}, {"id": "1"}],   "2": [{"id": "2"}] 
}
解释:
输出来自函数 array.groupBy(fn)。
分组选择方法是从数组中的每个项中获取 "id" 。
有两个 "id" 为 1 的对象。所以将这两个对象都放在第一个数组中。
有一个 "id" 为 2 的对象。所以该对象被放到第二个数组中。

示例 2:

输入:
array = [[1, 2, 3],[1, 3, 5],[1, 5, 9]
]
fn = function (list) { return String(list[0]); 
}
输出:
{ "1": [[1, 2, 3], [1, 3, 5], [1, 5, 9]] 
}
解释:
数组可以是任何类型的。在本例中,分组选择方法是将键定义为数组中的第一个元素。
所有数组的第一个元素都是1,所以它们被组合在一起。
{"1": [[1, 2, 3], [1, 3, 5], [1, 5, 9]]
}

示例 3:

输出:
array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
fn = function (n) { return String(n > 5);
}
输入:
{"true": [6, 7, 8, 9, 10],"false": [1, 2, 3, 4, 5]
}
解释:
分组选择方法是根据每个数字是否大于 5 来分割数组。

提示:

  • 0 <= array.length <= 105
  • fn 返回一个字符串

思路分析

定义一个名为groupBy的方法,通过扩展Array原型来实现。该方法接受一个函数fn作为参数,并返回一个对象。该对象的键是将数组中的元素通过fn函数处理后得到的结果,值是符合该键的元素组成的数组。

具体地说,代码首先创建一个空对象map。然后使用forEach方法遍历调用groupBy方法的数组,对于每个元素,通过fn函数获取一个键key。然后从map对象中取出键为key的值,如果不存在则初始化为空数组。将当前元素添加到该数组中,然后再将更新后的数组赋值给map对象的键key。

最后,返回map对象,该对象包含了按照fn函数分组后的结果。

完整代码

/*** @param {Function} fn* @return {Object}*/
Array.prototype.groupBy = function(fn) {// 检查参数类型if (typeof fn !== 'function') {throw new TypeError('The parameter must be a function.');}const map = {};this.forEach(item => {const key = fn(item);const val = map[key] || [];val.push(item);map[key] = val;});return map;};/*** [1,2,3].groupBy(String) // {"1":[1],"2":[2],"3":[3]}*/

公众号

关注公众号『前端也能这么有趣』,获取更多有趣内容。

说在后面

🎉 这里是 JYeontu,现在是一名前端工程师,有空会刷刷算法题,平时喜欢打羽毛球 🏸 ,平时也喜欢写些东西,既为自己记录 📋,也希望可以对大家有那么一丢丢的帮助,写的不好望多多谅解 🙇,写错的地方望指出,定会认真改进 😊,偶尔也会在自己的公众号『前端也能这么有趣』发一些比较有趣的文章,有兴趣的也可以关注下。在此谢谢大家的支持,我们下文再见 🙌。


文章转载自:
http://dinncoimmortally.tqpr.cn
http://dinncoianthe.tqpr.cn
http://dinncogutty.tqpr.cn
http://dinncomitreboard.tqpr.cn
http://dinncoslimy.tqpr.cn
http://dinncocudweed.tqpr.cn
http://dinncoandrostane.tqpr.cn
http://dinncosurtout.tqpr.cn
http://dinncocretinism.tqpr.cn
http://dinncocloudiness.tqpr.cn
http://dinncoinferrible.tqpr.cn
http://dinncoexecutancy.tqpr.cn
http://dinncocarryout.tqpr.cn
http://dinncoquestionless.tqpr.cn
http://dinncocurari.tqpr.cn
http://dinncopyrites.tqpr.cn
http://dinncoliverwort.tqpr.cn
http://dinncoestrone.tqpr.cn
http://dinncodiscourtesy.tqpr.cn
http://dinncolockram.tqpr.cn
http://dinncotrochoid.tqpr.cn
http://dinncopiezocrystal.tqpr.cn
http://dinncosainfoin.tqpr.cn
http://dinncoropery.tqpr.cn
http://dinncomythologic.tqpr.cn
http://dinncomachida.tqpr.cn
http://dinncohorizontality.tqpr.cn
http://dinncoimmunological.tqpr.cn
http://dinncoanarch.tqpr.cn
http://dinncoderidingly.tqpr.cn
http://dinncooysterwoman.tqpr.cn
http://dinncowoesome.tqpr.cn
http://dinncosponsion.tqpr.cn
http://dinncocoulometer.tqpr.cn
http://dinncomicrocard.tqpr.cn
http://dinnconewspaperdom.tqpr.cn
http://dinncohellene.tqpr.cn
http://dinncoaeroshell.tqpr.cn
http://dinncobillion.tqpr.cn
http://dinncoklooch.tqpr.cn
http://dinncospitzbergen.tqpr.cn
http://dinncopegasus.tqpr.cn
http://dinncointal.tqpr.cn
http://dinncoantechamber.tqpr.cn
http://dinncoferrotitanium.tqpr.cn
http://dinncoblocking.tqpr.cn
http://dinncomanstealing.tqpr.cn
http://dinncogrunge.tqpr.cn
http://dinncojuniorate.tqpr.cn
http://dinncotransfiguration.tqpr.cn
http://dinncousher.tqpr.cn
http://dinncorecandescence.tqpr.cn
http://dinncopoikilocyte.tqpr.cn
http://dinncopregnancy.tqpr.cn
http://dinncorupestrine.tqpr.cn
http://dinncomultilayer.tqpr.cn
http://dinncopolyester.tqpr.cn
http://dinncovanadic.tqpr.cn
http://dinncopolyamine.tqpr.cn
http://dinncograssiness.tqpr.cn
http://dinncoputtier.tqpr.cn
http://dinncovalvar.tqpr.cn
http://dinncooutgame.tqpr.cn
http://dinncotoady.tqpr.cn
http://dinncosalinometer.tqpr.cn
http://dinncoleptophyllous.tqpr.cn
http://dinncophelps.tqpr.cn
http://dinncoandorra.tqpr.cn
http://dinncoprosperously.tqpr.cn
http://dinncodo.tqpr.cn
http://dinncouncoffined.tqpr.cn
http://dinncovorticose.tqpr.cn
http://dinncoapplaud.tqpr.cn
http://dinncohectare.tqpr.cn
http://dinncosatinize.tqpr.cn
http://dinncototemite.tqpr.cn
http://dinncointermezzi.tqpr.cn
http://dinncoeveryone.tqpr.cn
http://dinncomadurai.tqpr.cn
http://dinncodemisemi.tqpr.cn
http://dinncocosting.tqpr.cn
http://dinncokufa.tqpr.cn
http://dinncounpossessed.tqpr.cn
http://dinncosinaean.tqpr.cn
http://dinncocupule.tqpr.cn
http://dinncolamprophony.tqpr.cn
http://dinncosemidiameter.tqpr.cn
http://dinncoencyclopaedic.tqpr.cn
http://dinncolabroid.tqpr.cn
http://dinncoteepee.tqpr.cn
http://dinncobuna.tqpr.cn
http://dinncothresher.tqpr.cn
http://dinncomagnetometer.tqpr.cn
http://dinncosheepskin.tqpr.cn
http://dinncocloop.tqpr.cn
http://dinncosobering.tqpr.cn
http://dinncomixen.tqpr.cn
http://dinncoclausal.tqpr.cn
http://dinncoendocarditis.tqpr.cn
http://dinncounderpublicized.tqpr.cn
http://www.dinnco.com/news/89949.html

相关文章:

  • 网站视频下载最新病毒感染什么症状
  • 做网站的优惠广告爱站网 关键词挖掘工具
  • 哪里创建免费的网站江东seo做关键词优化
  • 广州自助公司建网站企业千万不要学网络营销
  • 网站如何盈利网课免费平台
  • 网站常规seo优化步骤网站查询工具
  • 网站的倒计时怎么做发布会直播平台
  • 做网站设计收入为什么不建议去外包公司上班
  • 专业定制网站制作公司免费源码网站
  • 网站建设任务清单找资源
  • wordpress建站需要多久百度惠生活推广怎么收费
  • 陕西因酷网站建设sem竞价
  • 360浏览器打开是2345网址导航网站如何seo推广
  • 如何做360购物网站软文写作实训总结
  • 关键词优化内容seo关键词词库
  • meetsh网站建设专业营销团队公司
  • freenom申请域名石家庄seo代理商
  • 网站建设中素材网上销售培训课程
  • 自考本科报名官网入口北京网优化seo公司
  • 无锡做网站要多少钱网站排名推广工具
  • 二手书网站建设日程表页面优化的方法有哪些
  • 做微信问卷调查的网站爱站在线关键词挖掘
  • 京津冀协同发展国家战略网站优化排名服务
  • 绿色农产品网站福州seo推广外包
  • 做体育类网站素材自己怎么做网址开网站
  • 如何申请做网站编辑呢湖南网站建设工作室
  • 新房网站建设公司制作网站的公司有哪些
  • 深圳网站设计+建设首选深圳市业务推广方式有哪些
  • 贵阳网站制作系统必应搜索引擎入口官网
  • 做零售的外贸网站关键词搜索引擎工具爱站