Skip to content

Commit

Permalink
releases 3.5.32
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Nov 22, 2024
1 parent 65c661d commit 7a2fa02
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion func/sum.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var helperNumberAdd = require('./helperNumberAdd')

var isFunction = require('./isFunction')
var isArray = require('./isArray')
var each = require('./each')
var get = require('./get')

Expand All @@ -14,7 +15,7 @@ var get = require('./get')
*/
function sum (array, iterate, context) {
var result = 0
each(array, iterate ? isFunction(iterate) ? function () {
each(array && array.length > 2 && isArray(array) ? array.sort() : array, iterate ? isFunction(iterate) ? function () {
result = helperNumberAdd(result, iterate.apply(context, arguments))
} : function (val) {
result = helperNumberAdd(result, get(val, iterate))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xe-utils",
"version": "3.5.31",
"version": "3.5.32",
"description": "JavaScript 函数库、工具类",
"main": "index.js",
"unpkg": "dist/xe-utils.umd.min.js",
Expand Down
4 changes: 2 additions & 2 deletions src/views/API.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2812,8 +2812,8 @@ export default {
{
name: 'commafy',
args: 'num [, options]',
title: '数值千分位分隔符、小数点',
desc: '',
title: '数值与字符串分隔函数',
desc: '如果为数值,则按照金额千位分隔,如果为字符串则按照指定位数分隔',
params: [
['属性', '描述', '类型', '版本'],
['spaceNumber', '分割位数,默认3', 'number', ''],
Expand Down
27 changes: 27 additions & 0 deletions test/array.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,33 @@ describe('Array functions', () => {
expect(
XEUtils.sum({ val1: 21, val2: 34, val3: 47 })
).toEqual(102)
expect(
XEUtils.sum([0.26710027,
30, 3, 0.0175, 18, 0.0145, 0.38, 13, 15600, 0.7, 14, 1.57, 1, 30, 760, 0.15,
45, 1.6, 1, 1011.468, 13, 3, 1, 1.76, 0.018, 13, 15600, 3, 3, 80, 15600, 2.3,
14.6, 485, 0.2749008, 760, 2.3, 760, 13, 123, 109.073, 760, 0.68, 0.68, 1900,
14, 22.5, 1900, 1900, 15600, 2.05, 550, 1.23, 485, 13, 2.3, 0.2, 1900, 220,
760, 20, 13, 1900, 485, 2050, 30, 0.65, 1, 500, 1.68, 30, 0.015, 3, 14, 1, 3,
1.69, 13, 13, 1.68, 14.5, 1.75, 485
])
).toEqual(82733.09800107)
expect(
XEUtils.sum([0.26710027,
30, 3, 0.0175, 18, 0.0145, 0.38, 13, 15600, 0.7, 14, 1.57, 1, 30, 760, 0.15,
45, 1.6, 1, 1011.468, 13, 3, 1, 1.76, 0.018, 13, 15600, 3, 3, 80, 15600, 2.3,
14.6, 485, 0.2749008, 760, 2.3, 760, 13, 123, 109.073, 760, 0.68, 0.68, 1900,
14, 22.5, 1900, 1900, 15600, 2.05, 550, 1.23, 485, 13, 2.3, 0.2, 1900, 220,
760, 20, 13, 1900, 485, 2050, 30, 0.65, 1, 500, 1.68, 30, 0.015, 3, 14, 1, 3,
1.69, 13, 13, 1.68, 14.5, 1.75, 485
]) === XEUtils.sum([
30, 3, 0.0175, 18, 0.0145, 0.38, 13, 15600, 0.7, 14, 1.57, 1, 30, 760, 0.15,
45, 1.6, 1, 1011.468, 13, 3, 1, 1.76, 0.018, 13, 15600, 3, 3, 80, 15600, 2.3,
14.6, 485, 0.2749008, 760, 2.3, 760, 13, 123, 109.073, 760, 0.68, 0.68, 1900,
14, 22.5, 1900, 1900, 15600, 2.05, 550, 1.23, 485, 13, 2.3, 0.2, 1900, 220,
760, 20, 13, 1900, 485, 2050, 30, 0.65, 1, 500, 1.68, 30, 0.015, 3, 14, 1, 3,
1.69, 13, 13, 1.68, 14.5, 1.75, 485, 0.26710027
])
).toEqual(true)
})

test('mean()', () => {
Expand Down

0 comments on commit 7a2fa02

Please sign in to comment.