1+ <!DOCTYPE html> < html lang ="en "> < head > < meta charSet ="utf-8 "/> < meta http-equiv ="X-UA-Compatible " content ="IE=edge "/> < title > Numeric aggregation functions · JSONata</ title > < meta name ="viewport " content ="width=device-width, initial-scale=1.0 "/> < meta name ="generator " content ="Docusaurus "/> < meta name ="description " content ="## `$sum()` "/> < meta name ="docsearch:version " content ="2.0.0 "/> < meta name ="docsearch:language " content ="en "/> < meta property ="og:title " content ="Numeric aggregation functions · JSONata "/> < meta property ="og:type " content ="website "/> < meta property ="og:url " content ="http://docs.jsonata.org/ "/> < meta property ="og:description " content ="## `$sum()` "/> < meta name ="twitter:card " content ="summary "/> < link rel ="shortcut icon " href ="/img/jsonata-button.png "/> < link rel ="stylesheet " href ="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css "/> < script type ="text/javascript " src ="https://buttons.github.io/buttons.js "> </ script > < script type ="text/javascript " src ="/js/jsonata-examples.js "> </ script > < script src ="/js/scrollSpy.js "> </ script > < link rel ="stylesheet " href ="/css/main.css "/> < script src ="/js/codetabs.js "> </ script > </ head > < body class ="sideNavVisible separateOnPageNav "> < div class ="fixedHeaderContainer "> < div class ="headerWrapper wrapper "> < header > < a href ="/ "> < img class ="logo " src ="/img/jsonata-button.png " alt ="JSONata "/> < h2 class ="headerTitleWithLogo "> JSONata</ h2 > </ a > < a href ="/versions "> < h3 > 2.0.0</ h3 > </ a > < div class ="navigationWrapper navigationSlider "> < nav class ="slidingNav "> < ul class ="nav-site nav-site-internal "> < li class ="siteNavGroupActive "> < a href ="/2.0.0/overview " target ="_self "> Docs</ a > </ li > < li class =""> < a href ="http://try.jsonata.org " target ="_self "> Try</ a > </ li > < li class =""> < a href ="https://github.com/jsonata-js/jsonata " target ="_self "> GitHub</ a > </ li > < li class =""> < a href ="https://www.npmjs.com/package/jsonata " target ="_self "> NPM</ a > </ li > </ ul > </ nav > </ div > </ header > </ div > </ div > < div class ="navPusher "> < div class ="docMainWrapper wrapper "> < div class ="docsNavContainer " id ="docsNav "> < nav class ="toc "> < div class ="toggleNav "> < section class ="navWrapper wrapper "> < div class ="navBreadcrumb wrapper "> < div class ="navToggle " id ="navToggler "> < div class ="hamburger-menu "> < div class ="line1 "> </ div > < div class ="line2 "> </ div > < div class ="line3 "> </ div > </ div > </ div > < h2 > < i > ›</ i > < span > Function Library</ span > </ h2 > < div class ="tocToggler " id ="tocToggler "> < i class ="icon-toc "> </ i > </ div > </ div > < div class ="navGroups "> < div class ="navGroup "> < h3 class ="navGroupCategoryTitle "> Getting Started</ h3 > < ul class =""> < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/overview "> Overview</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/using-nodejs "> In NodeJS</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/using-browser "> In a Web Page</ a > </ li > </ ul > </ div > < div class ="navGroup "> < h3 class ="navGroupCategoryTitle "> Language Guide</ h3 > < ul class =""> < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/simple "> Simple Queries</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/predicate "> Predicate Queries</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/expressions "> Functions and Expressions</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/construction "> Result Structures</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/composition "> Query Composition</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/sorting-grouping "> Sorting, Grouping and Aggregation</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/processing "> Processing Model</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/programming "> Functional Programming</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/regex "> Regular Expressions</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/date-time "> Date/Time Processing</ a > </ li > </ ul > </ div > < div class ="navGroup "> < h3 class ="navGroupCategoryTitle "> Operators</ h3 > < ul class =""> < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/path-operators "> Path Operators</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/numeric-operators "> Numeric Operators</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/comparison-operators "> Comparison Operators</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/boolean-operators "> Boolean Operators</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/other-operators "> Other Operators</ a > </ li > </ ul > </ div > < div class ="navGroup "> < h3 class ="navGroupCategoryTitle "> Function Library</ h3 > < ul class =""> < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/string-functions "> String Functions</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/numeric-functions "> Numeric Functions</ a > </ li > < li class ="navListItem navListItemActive "> < a class ="navItem " href ="/2.0.0/aggregation-functions "> Aggregation Functions</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/boolean-functions "> Boolean Functions</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/array-functions "> Array Functions</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/object-functions "> Object Functions</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/date-time-functions "> Date/Time Functions</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/higher-order-functions "> Higher Order Functions</ a > </ li > </ ul > </ div > < div class ="navGroup "> < h3 class ="navGroupCategoryTitle "> Extending JSONata</ h3 > < ul class =""> < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/embedding-extending "> Embedding and Extending JSONata</ a > </ li > < li class ="navListItem "> < a class ="navItem " href ="/2.0.0/contributing "> Community and Contributing</ a > </ li > </ ul > </ div > </ div > </ section > </ div > < script >
2+ var coll = document . getElementsByClassName ( 'collapsible' ) ;
3+ var checkActiveCategory = true ;
4+ for ( var i = 0 ; i < coll . length ; i ++ ) {
5+ var links = coll [ i ] . nextElementSibling . getElementsByTagName ( '*' ) ;
6+ if ( checkActiveCategory ) {
7+ for ( var j = 0 ; j < links . length ; j ++ ) {
8+ if ( links [ j ] . classList . contains ( 'navListItemActive' ) ) {
9+ coll [ i ] . nextElementSibling . classList . toggle ( 'hide' ) ;
10+ coll [ i ] . childNodes [ 1 ] . classList . toggle ( 'rotate' ) ;
11+ checkActiveCategory = false ;
12+ break ;
13+ }
14+ }
15+ }
16+
17+ coll [ i ] . addEventListener ( 'click' , function ( ) {
18+ var arrow = this . childNodes [ 1 ] ;
19+ arrow . classList . toggle ( 'rotate' ) ;
20+ var content = this . nextElementSibling ;
21+ content . classList . toggle ( 'hide' ) ;
22+ } ) ;
23+ }
24+
25+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
26+ createToggler ( '#navToggler' , '#docsNav' , 'docsSliderActive' ) ;
27+ createToggler ( '#tocToggler' , 'body' , 'tocActive' ) ;
28+
29+ var headings = document . querySelector ( '.toc-headings' ) ;
30+ headings && headings . addEventListener ( 'click' , function ( event ) {
31+ var el = event . target ;
32+ while ( el !== headings ) {
33+ if ( el . tagName === 'A' ) {
34+ document . body . classList . remove ( 'tocActive' ) ;
35+ break ;
36+ } else {
37+ el = el . parentNode ;
38+ }
39+ }
40+ } , false ) ;
41+
42+ function createToggler ( togglerSelector , targetSelector , className ) {
43+ var toggler = document . querySelector ( togglerSelector ) ;
44+ var target = document . querySelector ( targetSelector ) ;
45+
46+ if ( ! toggler ) {
47+ return ;
48+ }
49+
50+ toggler . onclick = function ( event ) {
51+ event . preventDefault ( ) ;
52+
53+ target . classList . toggle ( className ) ;
54+ } ;
55+ }
56+ } ) ;
57+ </ script > </ nav > </ div > < div class ="container mainContainer docsContainer "> < div class ="wrapper "> < div class ="post "> < header class ="postHeader "> < a class ="edit-page-link button " href ="https://github.com/jsonata-js/jsonata/edit/master/docs/aggregation-functions.md " target ="_blank " rel ="noreferrer noopener "> Edit</ a > < h1 id ="__docusaurus " class ="postHeaderTitle "> Numeric aggregation functions</ h1 > </ header > < article > < div > < span > < h2 > < a class ="anchor " aria-hidden ="true " id ="sum "> </ a > < a href ="#sum " aria-hidden ="true " class ="hash-link "> < svg class ="hash-link-icon " aria-hidden ="true " height ="16 " version ="1.1 " viewBox ="0 0 16 16 " width ="16 "> < path fill-rule ="evenodd " d ="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z "> </ path > </ svg > </ a > < code > $sum()</ code > </ h2 >
58+ < p > < strong > Signature:</ strong > < code > $sum(array)</ code > </ p >
59+ < p > Returns the arithmetic sum of an array of numbers. It is an error if the input array contains an item which isn't a number.</ p >
60+ < p > < strong > Example</ strong > </ p >
61+ < ul >
62+ < li > < code > $sum([5,1,3,7,4])</ code > => < code > 20</ code > </ li >
63+ </ ul >
64+ < h2 > < a class ="anchor " aria-hidden ="true " id ="max "> </ a > < a href ="#max " aria-hidden ="true " class ="hash-link "> < svg class ="hash-link-icon " aria-hidden ="true " height ="16 " version ="1.1 " viewBox ="0 0 16 16 " width ="16 "> < path fill-rule ="evenodd " d ="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z "> </ path > </ svg > </ a > < code > $max()</ code > </ h2 >
65+ < p > < strong > Signature:</ strong > < code > $max(array)</ code > </ p >
66+ < p > Returns the maximum number in an array of numbers. It is an error if the input array contains an item which isn't a number.</ p >
67+ < p > < strong > Example</ strong > </ p >
68+ < ul >
69+ < li > < code > $max([5,1,3,7,4])</ code > => < code > 7</ code > </ li >
70+ </ ul >
71+ < h2 > < a class ="anchor " aria-hidden ="true " id ="min "> </ a > < a href ="#min " aria-hidden ="true " class ="hash-link "> < svg class ="hash-link-icon " aria-hidden ="true " height ="16 " version ="1.1 " viewBox ="0 0 16 16 " width ="16 "> < path fill-rule ="evenodd " d ="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z "> </ path > </ svg > </ a > < code > $min()</ code > </ h2 >
72+ < p > < strong > Signature:</ strong > < code > $min(array)</ code > </ p >
73+ < p > Returns the minimum number in an array of numbers. It is an error if the input array contains an item which isn't a number.</ p >
74+ < p > < strong > Example</ strong > </ p >
75+ < ul >
76+ < li > < code > $min([5,1,3,7,4])</ code > => < code > 1</ code > </ li >
77+ </ ul >
78+ < h2 > < a class ="anchor " aria-hidden ="true " id ="average "> </ a > < a href ="#average " aria-hidden ="true " class ="hash-link "> < svg class ="hash-link-icon " aria-hidden ="true " height ="16 " version ="1.1 " viewBox ="0 0 16 16 " width ="16 "> < path fill-rule ="evenodd " d ="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z "> </ path > </ svg > </ a > < code > $average()</ code > </ h2 >
79+ < p > < strong > Signature:</ strong > < code > $average(array)</ code > </ p >
80+ < p > Returns the mean value of an array of numbers. It is an error if the input array contains an item which isn't a number.</ p >
81+ < p > < strong > Example</ strong > </ p >
82+ < ul >
83+ < li > < code > $average([5,1,3,7,4])</ code > => < code > 4</ code > </ li >
84+ </ ul >
85+ </ span > </ div > </ article > </ div > < div class ="docs-prevnext "> < a class ="docs-prev button " href ="/2.0.0/numeric-functions "> < span class ="arrow-prev "> ← </ span > < span > Numeric Functions</ span > </ a > < a class ="docs-next button " href ="/2.0.0/boolean-functions "> < span > Boolean Functions</ span > < span class ="arrow-next "> →</ span > </ a > </ div > </ div > </ div > < nav class ="onPageNav "> < ul class ="toc-headings "> < li > < a href ="#sum "> < code > $sum()</ code > </ a > </ li > < li > < a href ="#max "> < code > $max()</ code > </ a > </ li > < li > < a href ="#min "> < code > $min()</ code > </ a > </ li > < li > < a href ="#average "> < code > $average()</ code > </ a > </ li > </ ul > </ nav > </ div > < footer class ="nav-footer " id ="footer "> < section class ="sitemap "> < a href ="/ " class ="nav-home "> < img src ="/img/jsonata-white-167.png " alt ="JSONata "/> </ a > < div > < h5 > JSONata</ h5 > < a href ="http://jsonata.org " target ="_blank " rel ="noreferrer noopener "> JSON query and< br /> transformation language</ a > < a href ="http://try.jsonata.org " target ="_blank " rel ="noreferrer noopener "> Go play in the< br /> JSONata Exerciser</ a > </ div > < div > < h5 > Community</ h5 > < a href ="https://stackoverflow.com/questions/tagged/jsonata " target ="_blank " rel ="noreferrer noopener "> Stack Overflow</ a > < a href ="https://jsonata.slack.com/ "> Project Chat</ a > < a href ="https://twitter.com/ " target ="_blank " rel ="noreferrer noopener "> Twitter</ a > </ div > < div > < h5 > More</ h5 > < a href ="https://github.com/jsonata-js/jsonata "> GitHub</ a > < a class ="github-button " href ="https://github.com/jsonata-js/jsonata " data-icon ="octicon-star " data-count-href ="/jsonata-js/jsonata/stargazers " data-show-count ="true " data-count-aria-label ="# stargazers on GitHub " aria-label ="Star this project on GitHub "> Star</ a > </ div > </ section > < section class ="copyright "> Copyright © 2021 JSONata.org</ section > </ footer > </ div > </ body > </ html >
0 commit comments