replace loops and custom functions with underscorejs untility functions

Signed-off-by: Connie <cleung334@gmail.com>