reverse every word
function reverseWords(str) {
const allWords = str.split(" ")
return allWords.map(item => item.split("").reverse().join("")).join(" ")
}
reverse every word
function reverseWords(str) {
const allWords = str.split(" ")
return allWords.map(item => item.split("").reverse().join("")).join(" ")
}
reverse each word
string reverse(string &s)//this func reverses single words
{
string r;
for(int i=s.size()-1;i>=0;i--)
{
r+=s[i];
}
return r;
}
//Function to reverse words in a given string.
string reverseWords(string s)
{
// we are reversing eachword from the end adn adding
string k,ans;
for(int i=s.size()-1;i>=0;i--)
{
if(s[i]=='.')
{
k=reverse(k);
ans+=k;ans+='.';
k.clear();
continue;
}
k+=s[i];
}
ans+=reverse(k);
return ans;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us