New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jkg-array-column-sum

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jkg-array-column-sum

`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:

  • 2.0.11
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
6
decreased by-72.73%
Maintainers
1
Weekly downloads
 
Created
Source

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:

  • Angular - Stackblitz DEMO

  • Node JS - Stackblitz DEMO

  • React Js - Stackblitz 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.

Keywords

FAQs

Package last updated on 18 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc