Search⌘ K
AI Features

Challenge: Make a Sentence

Discover how to implement partial functions in JavaScript to construct sentences by combining words with a conjunction. This lesson helps you understand passing functions and arguments in a functional programming style. You'll practice creating higher-order functions and test your implementation to produce correctly formatted sentences.

Problem statement

Study the code given below:

Javascript (babel-node)
const sentence = (conjunction, ...otherWords) => {
const commasJoiningWords = otherWords.slice(0,-1).join(", ");
const lastWord = otherWords.pop();
return `${commasJoiningWords} ${conjunction} ${lastWord}`;
}
console.log(sentence("and","mango","apple","peach"))
console.log(sentence("or","bike","car","train"))

Observe the output and then try to understand what the sentence function is doing. Currently, on ...