Solving: sentenceReverse

Question

You are given an array of characters arr that consists of sequences of characters separated by space characters. Each space-delimited sequence of characters defines a word.

Implement a function reverseWords that reverses the order of the words in the array in the most efficient manner.

input:  arr = [ 'p', 'e', 'r', 'f', 'e', 'c', 't', '  ',
'm', 'a', 'k', 'e', 's', ' ',
'p', 'r', 'a', 'c', 't', 'i', 'c', 'e' ]
output: [ 'p', 'r', 'a', 'c', 't', 'i', 'c', 'e', ' ',
'm', 'a', 'k', 'e', 's', ' ',
'p', 'e', 'r', 'f', 'e', 'c', 't' ]

Conclusion

--

--

--

Just another one of those dreamers with a sparkle in his eyes.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Next Generation

Java Script Looping Statements

The Biggest Change in React 17 That No One Is Talking About

Performance optimization with React Hooks — useCallback & useMemo

UI Kitten vs Shoutem for React Native CSS frameworks comparison

Let’s Dive into Event Listeners

React Native — The full authentication flow— Introduction

How we built a component library that people actually enjoy using

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Janu Sung

Janu Sung

Just another one of those dreamers with a sparkle in his eyes.

More from Medium

Straight forward implementation of global state in React, with independently updated target…

cs371p Spring 2022 Week 3: Badr Belhiti

Difference Between Class Based And Function Based Components (REACT.JS) [Which is Better?]

Regular Function vs Arrow Function [en]