Grubhub Interview Question: Write a function to reverse a... |

Interview Question

Software Engineer Interview

Write a function to reverse all the words in a string

  separated by spaces. There will be k spaces, and k + 1 words.

Interview Answer

3 Answers


var rev = function ( x ){
    return x.split(" ").reverse().join(" ");

Anonymous on 2 Jun 2015

def reverse_sentence(words):
    return ' '.join([word for word in words.split()[::-1]])

In Python on 2 Sep 2016

One or more comments have been removed.
Please see our Community Guidelines or Terms of Service for more information.

Add Answers or Comments

To comment on this, Sign In or Sign Up.