Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

compute-io / argmax / 9

9 Jun 2015 - 5:16 coverage: 97.059% (-2.9%) from 100.0%
9

Pull #1

travis-ci

88cba5f6ee044b057480fe2cff63825b?size=18&default=identiconkgryte
[UPDATE] dependencies
Pull Request #1: Update according to TODO

98 of 101 new or added lines in 5 files covered. (97.03%)

99 of 102 relevant lines covered (97.06%)

36.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.75
/lib/accessor.js
1
'use strict';
2

3
/**
4
* FUNCTION: max( arr, clbk )
5
*        Computes the maximum value of an array using an accessor.
6
*
7
* @param {Array} arr - input array
8
* @param {Function} [accessor] - accessor function for accessing array values
9
* @returns {Number[]|Null} maximum value indices
10
*/
11
function argmax( arr, clbk ) {
3×
12
        var len = arr.length,
9×
13
                max,
14
                i, v,
15
                idx;
16

17
        if ( !len ) {
9×
18
                return null;
3×
19
        }
20

21
        max = clbk( arr[ 0 ], 0 );
6×
22
        idx = [ 0 ];
6×
23
        for ( i = 1; i < len; i++ ) {
6×
24
                v = clbk( arr[ i ], i );
30×
25
                if ( v > max ) {
30×
26
                        max = v;
18×
27
                        idx.length = 0;
18×
28
                        idx.push( i );
18×
29
                }
30
                else if ( v === max ) {
12×
NEW
31
                        idx.push( i );
!
32
                }
33
        }
34

35
        return idx;
6×
36
} // end FUNCTION argmax()
37

38

39
// EXPORTS //
40

41
module.exports = argmax;
3×
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc