I'm trying to write a function on which if we pass the string like we do for split, it returns a string which is reversed -
This is what I've tried -
var abc = "hello"
var result;
String.prototype.reverser = function(str){
var temparr = str.split('').reverse().join('');
return temparr;
}
result = abc.reverser();
console.log(result);
I'm expecting olleh but rather getting -
VM1179:4 Uncaught TypeError: Cannot read property 'split' of undefined at String.reverser (:4:19) at :7:14