1.0.3 • Published 3 years ago
emotools v1.0.3
安装 npm install emotools
数组
比较
1. addAndMinus
用途:两个数组 let a=[3,4] let b=[4,5]
比较数组 b相对于a新增的和删除的元素 即 ab差集 ba差集
参数:
* @param {*} oldArray 原始数组
* @param {*} newArray 新增数组
* @param {*} type 想要得到的数据类型 [[],[]] 或 {remove: [ ], add: [ ]} 默认为数组
* @param {*} tip 控制台输出提示 默认不显示 tip传为true打印
用法:
import {addAndMinus} from 'emotools';
<!-- 基本用法 -->
const test1 = addAndMinus([3,4],[3,9]) // [[4],[9]]
<!-- 想要对象数据类型 -->
const test2 = addAndMinus([3,4],[3,9],{}) // {remove:[4],add:[9]}
<!-- 想要控制台的提示 -->
const test3 = addAndMinus([3,4],[3,9],{},true)
2. commonElement
用途:比较两个数组相同的元素
参数:
* @param {*} arrayA 数组A
* @param {*} arrayB 数组B
* @param {*} unique 是否去重 默认去重
* @param {*} tip 控制台输出提示 默认不显示 tip传为true打印
* @returns
用法:
<!-- 基本用法 -->
const test1 = commonElement([1, 2], [2, 2, 3]) // [2]
<!-- 不去重 -->
const test2 = commonElement([1, 2], [2, 2, 3],false) // [2,2]
<!-- 想要控制台的输出 -->
const test2 = commonElement([1, 2], [2, 2, 3],false,true)