I am trying to create a function that will take a list of words -- and covert it into a sentence like this.
jsfiddle
http://jsfiddle.net/0ht35rpb/107/
<
One way is to pop off the last item, and then join and place the last item within the sting
function grammarCheck(vals) {
//x,y,z and d
//z
var count = vals.length;
var last = vals.pop()
var text = vals.join(', ') + (vals.length > 1 ? ' and ' : '') + last
return text
}
var arr = [
["emotional distress"],
["abc", "123", "blah", "blah", "blah"]
]
arr.forEach(a => console.log('grammar check', grammarCheck(a)))