2.0.11 • Published 1 year ago

jkg-array-column-sum v2.0.11

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

getColumnSum

getColumnSum is an npm package for calculating the total sum of a column of numbers in an array of arrays, where each inner array represents a row of data. The package exports a single function getColumnSum that takes in four arguments:

  • lists: an array of arrays representing the data
  • index: an array of strings representing the column headers
  • isTypeArray (optional, default: true): a boolean indicating whether the result should be an array of strings or a single integer
  • decimalNumber (optional, default: 2): the number of decimal places to round the result to

Import the "getColumnSum" function into your component or service by adding the following code:

import getColumnSum from 'jkg-array-column-sum';

Live DEMO:

Call the "getColumnSum" function with a array, column names like 'column-name-1','column-name-2',... & format type: to get total value, like this:

Test Cases for method:

    var data = [
        ['id','date','Amount'], 
        ['1','111','123'], 
        ['2','121','13']
    ];

    var result = getColumnSum(data,[],false) 
    // By default it will consider defined columns 'Amount','Additions','Subtractions'
    // Output > 136
    
    var result = getColumnSum(data,['Amount'],false)
    // Output > 136
    
    var result = getColumnSum(data,['Amount'],true)
    // Output > Array ["", "", "Total: 136.00"]

    var result = getColumnSum(data, ['date', 'Amount'], true);
    // Output > Array ["", "Total: 232.00", "Total: 136.00"]

    var result = getColumnSum(data,['Amounts'],false)
    // Output > 0

    var result = getColumnSum(data,['Amounts'],true)
    // Output > Array []

License

This package is licensed under the MIT License.

2.0.11

1 year ago

2.0.10

1 year ago

2.0.9

1 year ago

2.0.8

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.35

1 year ago

1.0.34

1 year ago

1.0.33

1 year ago

1.0.32

1 year ago

1.0.31

1 year ago

1.0.30

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago