1// method to extend String to call reduce the same way as an Array
2String.prototype.reduce = function () {
3 return this.split().reduce(...arguments);
4}
5
6// sum of the ascii codes using the newly created String prototype method
7str.reduce((a,b) => a + b.charCodeAt(0), 0);
1let str = "hello";
2// reduce string to the sum of the ascii codes of its characters
3str.split().reduce((a,b) => a + b.charCodeAt(0), 0);