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

8 propositions that will improve your React Application

Relay Integration Test with Jest

Building your own templating engine in angular

Prototype in JavaScript

A 80/20 Guide to a Performant Web App

Augury Debugger Tool for Angular Development

Getting started with JQuery

Did you know that about JavaScript?

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

Javascript in Leetcode 07–09 | 面試問題

7 Must known array functions 🍻 ft.Js

Callback, Promises & Async/Await The Difference!

Construct a binary tree from given multi-dimensional array