RSSAmplifier

(untitled) · May 22, 2015

How to find the maximum value in an array

0
Sign in to vote or save

This site does not allow itself to be embedded. You can still read it on the original site — the toolbar below keeps your place in the directory.

Find the maximum value in an array. function max(col, fn) { var top = - Infinity ; var index; if ( Array .isArray(col)) { for ( var i = 0 ; i < col.length; i ++ ) { var result = col[i]; if ( typeof fn === 'function' ) { result = fn(col[i]); } else if ( typeof fn === 'string' ) { result = col[i][fn]; } if (result >= top) { top = result; index = i; } } } return typeof index !== 'undefined' ?…

Read on miguelmota.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.