Fixed early termination issue

Fixed early termination issue when the source array contained undefined
values. Also added a html file for tests.