
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
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
- Related Articles
- Finding special kind of elements with in an array in JavaScript
- Checking smooth sentences in JavaScript
- Finding average word length of sentences - JavaScript
- Finding special array - JavaScript
- Finding special type of numbers - JavaScript
- Finding count of special characters in a string in JavaScript
- ‘Osmosis is a special kind of diffusion’. Comment.
- Special arrays in JavaScript
- Grouping of same kind of numbers in JavaScript
- Special type of numbers (pronic) in JavaScript
- Special type of sorting algorithm in JavaScript
- Finding number of alphabets, digits and special characters in strings using C language
- Finding persistence of number in JavaScript
- Finding sum of multiples in JavaScript
- Finding score of brackets in JavaScript

Advertisements