Refactor the methods of Array.prototype