第一阶段基础算法
1.字符串
问:
输入: "Let's take LeetCode contest" 输出: "s'teL ekat edoCteeL tsetnoc"
使用jest测试并解答:
sum.js
function sum(str) {
//变成数组
const words = str.split(" ");
const wordsReverse = words.map((word) => {
return word.split("").reverse().join('');
});
return wordsReverse.join(" ");
}
module.exports = sum
sum.test.js
const sum = require('./sum.js')
test("zhuyu", () => {
expect(sum("Let's take LeetCode contest")).toBe("s'teL ekat edoCteeL tsetnoc");
})