当前位置:网站首页>JS小技巧,让你编码效率杠杠的,快乐摸鱼
JS小技巧,让你编码效率杠杠的,快乐摸鱼
2022-08-11 05:29:00 【wendZzz】
寻找最大值最小值,求和
reduce版
总和
var array = [1,2,3,4,5] array.reduce((a, b) => a + b)
示例:

最大值
var array = [12, 34, 22, 32, 21] array.reduce((a, b) => a > b ? a : b)
示例:

最小值
var array = [12, 34, 22, 32, 21] array.reduce((a, b) => a < b ? a : b)
示例:

排序
字符串排序
升序
var array = ["jack", "lucy", "bert", "tom", "beenle", "lirika"] array.sort()
示例:

降序
var array = ["jack", "lucy", "bert", "tom", "beenle", "lirika"] array.sort().reverse()
示例:

过滤数组中假值
var array = [1, "11", 0, "0", false, true, null, undefined, ''] array.filter(Boolean)
示例:

去重
数字去重
var array = [1,2,3,4,5,1,3,5,6] [...new Set(array)]
示例:

对象数组去重
/**
* arr: 作用数组
* uniKey: 去重字段
*/
function uniqueFunc(arr, uniKey){
const res = new Map();
return arr.filter((item) => !res.has(item[uniKey]) && res.set(item[uniKey], 1));
}示例:

边栏推荐
- Event Preview | On April 23, a number of wonderful sharing sessions of OpenMLDB will come, which will live up to the good time of the weekend
- 开源之夏 2022 火热来袭 | 欢迎报名 OpenMLDB 社区项目~
- 127.0.0.1 已拒绝连接
- Day 85
- 论文解读TransFG: A Transformer Architecture for Fine-grained Recognition
- [Meetup]OpenMLDBxDolphinScheduler 链接特征工程与调度环节,打造端到端MLOps工作流
- [Meetup] OpenMLDBxDolphinScheduler engineering and scheduling link link characteristics, building the end-to-end MLOps workflow
- Day 77
- vim 编辑解决中文乱码问题
- 实时特征计算平台架构方法论和基于 OpenMLDB 的实践
猜你喜欢

vscode插件开发——懒人专用markdown插件开发

Node stepping on the pit 80 port is occupied

STM32-库函数-SetSysClock(void)函数解析-正点原子探索者

STM32学习笔记(白话文理解版)—搞懂PWM输出

第四范式OpenMLDB优化创新论文被国际数据库顶会VLDB录用

论文解读:GAN与检测网络多任务/SOD-MTGAN: Small Object Detection via Multi-Task Generative Adversarial Network

STM32 基于固件库的工程模板的建立

Building a data ecology for feature engineering - Embrace the open source ecology, OpenMLDB fully opens up the MLOps ecological tool chain

场景驱动的特征计算方式OpenMLDB,高效实现“现算先用”

OpenMLDB:线上线下一致的生产级特征计算平台
随机推荐
Day 85
Thesis unscramble TransFG: A Transformer Architecture for Fine - grained Recognition
Jetpack使用异常问题集锦
Here is a memorial
SearchGuard配置
Jetpack's dataBinding
JS advanced web page special effects (pink teacher notes)
STM32学习笔记(白话文理解版)—外部IO中断实验
Building a data ecology for feature engineering - Embrace the open source ecology, OpenMLDB fully opens up the MLOps ecological tool chain
智能风控中台设计与落地
实时特征计算平台架构方法论和基于 OpenMLDB 的实践
OpenMLDB官网升级,神秘贡献者地图带你快速进阶
JS case exercise (classic case of teacher pink)
Day 83
构建面向特征工程的数据生态 ——拥抱开源生态,OpenMLDB全面打通MLOps生态工具链
贡献者任务第三期精彩来袭
vscode插件开发——代码提示、代码补全、代码分析(续)
Regular expression replacement for batch quick modification code
STM32学习笔记(白话文理解版)—搞懂PWM输出
活动预告 | 4月23日,多场OpenMLDB精彩分享来袭,不负周末好时光