Words to Sentence

Published by Enkuryo in

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(["edabit"]) ➞ "edabit"

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. "").

Watch a quick demo on how Edabit works.