function x(c) { for (var d = 5, a = 0, b = 0; b < c.length; b++) a *= d, a += c[b], d++; return a }; alert([x([4]),x([4,5]),x([4,5,6]),x([4,5,6,7])])