在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
热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短