Using Reduce Method Javascript Substring Syntax Java