javascript - 如何在 JavaScript 中删除撇号?
问题描述
这是针对预科课程 Thinkful 的挑战之一,所以这实际上不是一个问题,我可能会因为作弊或类似的事情而遇到麻烦,但我粘贴了问题和期望结果如下的代码哦,我只是无法做到这一点,我已经尝试了一切。
Diego 有两首歌曲的歌词,他想在他的网站上显示。第一个是“见一千件事”,另一个是“我们都是光”。歌曲标题以小写文本且没有标点符号存储在数据库中,因此要找到正确的歌词,我们需要转换 songTitle 变量以匹配存储在数据库中的内容。你能用你对字符串方法的知识来:1)小写songTitle变量和2)从songTitle中删除所有撇号吗?
Time: 6762msPassed: 1Failed: 1Exit Code: 1
Test Results:
Seen
a Thousand Things
should lowercase the text in the song title 'Seen a Thousand Things'
We're all Light
should remove the apostrophe and lowercase the text in the song title 'We're all light'
Test Failed
Failure
Error: expect(received).toMatch(expected)
Expected substring: "were all light"
Received string: "we're all light"
Completed in 3ms
Failures
● We're all Light › should remove the apostrophe and lowercase the text in the song title 'We're all light'
expect(received).toMatch(expected)
Expected substring: "were all light"
Received string: "we're all light"
13 | it("should remove the apostrophe and lowercase the text in the song title 'We're all light'", () => {
14 | let songTitle = "We're all light"
> 15 | expect(setSongTitle(songTitle)).toMatch("were all light");
| ^
16 | })
17 | })
at Object.toMatch (test/script.test.js:15:37)
以下是我尝试过的方法:
songTitle.replace("[\s']","","ALL"); (failed),
songTitle.replace(/[']+/g,""));