Skip to content

Latest commit

 

History

History
25 lines (24 loc) · 5.11 KB

20-format-words-into-a-sentence.md

File metadata and controls

25 lines (24 loc) · 5.11 KB

Problem:

Complete the method so that it formats the words into a single comma separated value. The last word should be separated by the word 'and' instead of a comma. The method takes in an array of strings and returns a single formatted string. Empty string values should be ignored. Empty arrays or null/nil values being passed into the method should result in an empty string being returned.

formatWords(['ninja', 'samurai', 'ronin']) // should return "ninja, samurai and ronin"
formatWords(['ninja', '', 'ronin']) // should return "ninja and ronin"
formatWords([]) // should return ""
formatWords(['ninja', 'samurai', 'ronin']) # should return "ninja, samurai and ronin"
formatWords(['ninja', '', 'ronin']) # should return "ninja and ronin"
formatWords([]) # should return ""
format_words(['ninja', 'samurai', 'ronin']) # should return "ninja, samurai and ronin"
format_words(['ninja', '', 'ronin']) # should return "ninja and ronin"
format_words([]) # should return ""
Kata.FormatWords(new string[] {"ninja", "samurai", "ronin"}) => "ninja, samurai and ronin"
Kata.FormatWords(new string[] {"ninja", "", "ronin"}) => "ninja and ronin"
Kata.FormatWords(new string[] {}) => ""
Kata.formatWords(new String[] {"ninja", "samurai", "ronin"}) => "ninja, samurai and ronin"
Kata.formatWords(new String[] {"ninja", "", "ronin"}) => "ninja and ronin"
Kata.formatWords(new String[] {}) => ""
format_words(['ninja', 'samurai', 'ronin']) # should return "ninja, samurai and ronin"
format_words(['ninja', '', 'ronin']) # should return "ninja and ronin"
format_words([]) # should return ""
formatWords ['ninja', 'samurai', 'ronin'] -- should return "ninja, samurai and ronin"
formatWords ['ninja', '', 'ronin'] -- should return "ninja and ronin"
formatWords [] -- should return ""

Solution