var secondMax = function (){ var arr = [20, 120, 111, 215, 54, 78];
demo
UPDATE
As davin pointed out , performance can be improved by not splicing, but temporarily replacing the -Infininty maximum value:
var secondMax = function (arr){ var max = Math.max.apply(null, arr),
In any case, IMHO the best algorithm is Jack. 1 pass, with the transition to the number. The mine is just short, using the built-in methods and just wanted to present it as an alternative to show all the different ways to achieve the goal.
source share