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

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.
Answer

Interview Answer

3 Answers

0

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

Anonymous on 2 Jun 2015
2

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

In Python on 2 Sep 2016
0

If you're looking for interview questions, try Rooftop Slushie - it's the easiest way to get questions and answers from current employees at Google, Facebook, Grubhub, and +50,000 companies.

https://wwww.rooftopslushie.com

Anonymous on 11 Jul 2019

Add Answers or Comments

To comment on this, Sign In or Sign Up.