es6的_.unionBy和Math.floor的用法

import * as _ from 'lodash';
 
const arr= _.unionBy([2.1,1.2,2.9,1.8,3.5,9.6],Math.floor);
console.log('arr:'+arr);
 
返回结果:arr:2.1,1.2,3.5,9.6
 
unionBy用来对数组去重,
 
Math.floor返回小于或等于一个给定数字的最大整数,就是向下取整,例如:

Math.floor( 45.95);
// 45
Math.floor( 45.05);
// 45
Math.floor( 4 );
// 4
Math.floor(-45.05);
// -46
Math.floor(-45.95);
// -46

 
 
posted @ 2021-03-05 11:07  密蒙  阅读(226)  评论(0编辑  收藏  举报