var arr = [1,2,2,1,1,1,1,1,0,0,0,0,2,1,1,2,0,0,2,1]; function foo(b, c) { return b.reduce(function(a, b) { a.temp = b == c ? ++a.temp : 0; a.temp > a.max && (a.max = a.temp); return a }, { temp: 0, max: 0 }).max }; alert(foo(arr,0))