Challenge: Make a Sentence
This challenge will test your skills in implementing partial functions in JavaScript.
We'll cover the following...
Problem statement #
Study the code given below:
Press + to interact
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 line 6 we are calling our function as follows:
sentence("and","mango","apple","peach")
...