javascript - JavaScript 数组 reduce() 累加器为空
问题描述
我正在拆分一个单词并将每个单独的元素转换为莫尔斯电码。但是,返回值为空。不知道我在这里做错了什么。
wordTransformed = word.split("").reduce((total, letter) => {
currentLetterIndex = alphabet.indexOf(letter);
total + morseAlphabet[currentLetterIndex];
return total
},"");
console.log(wordTransformed);
解决方案
total + morseAlphabet[currentLetterIndex];
您正在寻找
total += morseAlphabet[currentLetterIndex];
推荐阅读
- http - 使用 Wget 从网络请求中下载文件
- pdf - 如何在运行 Ghostscript 处理时保留 PDF 中未处理的页面?
- azure - 天蓝色。未找到订阅
- nginx - 路径的 Kubernetes 入口白名单 IP
- javascript - 在 TOR 中强制使用不同的电路
- html - 过滤特定页面上的 Blogger 帖子
- python - 在 pandas 数据框中查找元素的最新值
- python - 用于拟合正弦波的神经网络
- docker - 存储库“https://download.docker.com/linx/ubuntu bionic Release”没有发布文件
- c# - 继承类的 Moq 测试总是返回 null