Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

reverse every word

function reverseWords(str) {
  const allWords = str.split(" ")
  return allWords.map(item => item.split("").reverse().join("")).join(" ")
}
Comment

reverse every word of given sring

// C++ program to reverse individual words in a given
// string using STL list
#include <bits/stdc++.h>
using namespace std;
 
// reverses individual words of a string
void reverseWords(string str)
{
    stack<char> st;
 
    // Traverse given string and push all characters
    // to stack until we see a space.
    for (int i = 0; i < str.length(); ++i) {
        if (str[i] != ' ')
            st.push(str[i]);
 
        // When we see a space, we print contents
        // of stack.
        else {
            while (st.empty() == false) {
                cout << st.top();
                st.pop();
            }
            cout << " ";
        }
    }
 
    // Since there may not be space after
    // last word.
    while (st.empty() == false) {
        cout << st.top();
        st.pop();
    }
}
 
// Driver program to test function
int main()
{
    string str = "Geeks for Geeks";
    reverseWords(str);
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js trigger window resize 
Javascript :: react native text get number of lines 
Javascript :: generate random id javascript 
Javascript :: history.push with params 
Javascript :: cube root of a number in js 
Javascript :: loop array in javascript 
Javascript :: iframe chrome devtool 
Javascript :: disable scroll on modal open 
Javascript :: remove brackets from array javascript 
Javascript :: onloadscroll to top 
Javascript :: Prevent Double Submit with JavaScript 
Javascript :: convert elements to array javascript 
Javascript :: jquery option selected 
Javascript :: create react portal 
Javascript :: replace class js 
Javascript :: object length javascript 
Javascript :: how to read file extension in a folder in node js 
Javascript :: express redirect 
Javascript :: react addeventlistener useeffect 
Javascript :: for range python javascript 
Javascript :: check if new user in firebase react 
Javascript :: check if string contains substring javascript 
Javascript :: file picker electron 
Javascript :: momentjs range 
Javascript :: jquery wp disable 
Javascript :: regex char and number 
Javascript :: addEventListener call only once 
Javascript :: create an array of numbers 
Javascript :: add active class to li onclick react 
Javascript :: how to iterate over keys in object javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =