Reduce Function In Javascript Stack Overflow