function value([a, ...b]){ a % 2 && (a = 0); return b.length ? +a + value(b) : +a } console.log(value("254886"))