1'use strict' 2module.exports = qw 3 4function appendLast (arr, str) { 5 var last = arr.length - 1 6 if (last < 0) { 7 arr.push(str) 8 } else { 9 var lastValue = String(arr[last]) 10 return arr[last] = lastValue + String(str) 11 } 12} 13 14function qw () { 15 const args = Object.assign([], arguments[0]) 16 const values = [].slice.call(arguments, 1) 17 const words = [] 18 let lastWordWasValue = false 19 while (args.length) { 20 const arg = args.shift() 21 const concatValue = arg.length === 0 || arg.slice(-1) !== ' ' 22 if (arg.trim() !== '') { 23 const theseWords = arg.replace(/^\s+|\s+$/g, '').replace(/\s+/g, ' ').split(/ /) 24 if (lastWordWasValue && arg[0] !== ' ') { 25 appendLast(words, theseWords.shift()) 26 } 27 words.push.apply(words, theseWords) 28 } 29 30 if (values.length) { 31 const val = values.shift() 32 if (concatValue) { 33 appendLast(words, val) 34 } else { 35 words.push(val) 36 } 37 lastWordWasValue = true 38 } else { 39 lastWordWasValue = false 40 } 41 } 42 return words 43} 44