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

 
 
原文地址:https://www.cnblogs.com/mimeng/p/14485003.html