javascript functional programing example