reimplemented basic map function in js