javascript - 破译任何传递的字符串
问题描述
我正在 Codewars 上尝试这个问题。我不确定这样做是否正确。这是问题:
您会收到一条需要破译的秘密信息。以下是你需要知道的东西来破译它:
对于每个单词:
the second and the last letter is switched (e.g. Hello becomes Holle)
the first letter is replaced by its character code (e.g. H becomes 72)
注意:没有使用特殊字符,只有字母和空格:
decipherThis('72olle 103doo 100ya'); // 'Hello good day'
decipherThis('82yade 115te 103o'); // 'Ready set go'
现在我写了这段代码:
function decipherThis(str)
{
var msg = [];
msg.push(str.charCodeAt(0));
for (var i = 0; i<str.length; i++)
{
if (str[1] == true && str[1] != str[str.length])
{
msg.push(str[str.length]);
//str[1] = str[str.length]);
var news = str;
for (var j = 0; j<news.length; j++)
{
news[1] = news[news.length];
const newNew = delete news[0][1];
msg.push(newNew);
}
}
}
return msg;
};
var google = "hello"
decipherThis(google)
我收到一个错误,我想我已经为一个单词创建了它。它不理解空格后的单词。请帮我解决这个问题。这是错误回溯:
Response received but no data was written to STDOUT or STDERR.
解决方案
请更改characterCodeAt
为 charCodeAt
,它将起作用。
characterCodeAt
不是 String 类的有效方法
推荐阅读
- python - Django Rest Framework,用户模型出错
- ruby-on-rails - 循环赛中粘性会话的 Nginx 配置更改
- amazon-web-services - 如何在 SNS 上向上传的新对象发送带有预签名 URL 的 S3 存储桶通知?
- asp.net-web-api - Asp.net core web api Localization DataAnnotation 自定义属性
- mysql - 上周(周一至周日)项目 SQL
- javascript - JavaScript RGB 字符串 (`rgb(r, g, b)`) 到 HEX (`#rrggbb`) 转换
- php - 更新多个表
- android - 如何解决android中的Sinch Invalid signature错误
- ios - 是否可以在 App Store Connect/iTunes Search API 中看到分阶段的应用发布?
- prolog - Prolog - 递归访问列表的列表元素并获取总和