Using Reduce Method Javascript Substring Indexof