added test for Array last if invalid number is passed,refactoring