string reduction javascript

Solutions on MaxInterview for string reduction javascript by the best coders in the world

showing results for - "string reduction javascript"
Johann
25 Nov 2016
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);
Ilies
26 Nov 2017
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);