
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Finding Special Kind of Sentences Smooth in JavaScript
We are required to write a JavaScript function that checks whether a sentence is smooth or not.
A sentence is smooth when the first letter of each word in the sentence is the same as the last letter of its preceding word.
Therefore, let’s write the code for this function −
Example
The code for this will be −
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))
Output
The output in the console will be −
true false
Advertisements