查找字符串的 ASCII 分数 - JavaScript
ASCII 码
ASCII 是一种 7 位字符代码,其中的每个位都表示一个唯一的字符。
每个英语字母都具有唯一的十进制 ASCII 码。
我们需要编写一个 JavaScript 函数,该函数获取一个字符串并计算字符串字符的所有 ASCII 码的总和
示例
以下是代码 −
const str = 'This string will be used for calculating ascii score';
const calculateASCII = str => {
let res = 0;
for(let i = 0; i < str.length; i++){
const num = str[i].charCodeAt(0);
res += num;
};
return res;
};
console.log(calculateASCII(str));输出
以下是控制台中输出 −
4946
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP