← Back to challenges

Words to Sentence

JavaScriptHardarraysalgorithmsstringsformatting

Instructions

Create a function that turns an array of words into a comma separated list, where the last word is separated by the word "and".

Examples

wordsToSentence(["innokodakademija"]) ➞ "innokodakademija"

wordsToSentence(["Hello", "", "Bye"]) ➞ "Hello and Bye"

wordsToSentence(["Hello", "Bye", "See you soon"]) ➞ "Hello, Bye and See you soon"

Notes

null values, empty arrays or arrays with only empty or null values should return an empty string (e.g. "").

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.