在JavaScript中检查流畅的句子
我们需要编写一个JavaScript函数来检查句子是否平滑。当句子中每个单词的第一个字母与其前一个单词的最后一个字母相同时,该句子是平滑的。
示例
以下是代码-
const str = 'this stringt tries sto obe esmooth';
const str2 = 'this string is not smooth';
const isSmooth = str => {
const strArr = str.split(' ');
for(let i = 0; i < strArr.length; i++){
if(!strArr[i+1] || strArr[i][strArr[i].length -1] === strArr[i+1]
[0]){
continue;
};
return false;
};
return true;
};
console.log(isSmooth(str));
console.log(isSmooth(str2))输出结果
以下是控制台中的输出-
true false
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿