Few links
using 'map' to iterate over an array
It can replace a for loop, basically
Shorter syntax to write functions (ECMAscript 2015)
(ECMAscript 2015)
Writing test cases here is not that easy , since everything is random
const generateComment = array => array.map(x=>x[Math.floor(Math.random() * x.length)]).join` ` // console.log(generateComment([['hi,', 'hello,', 'hey,'], ['how are'], ['you', 'ya'], ['doing', 'going'], ['?', '?!', '']]));
var generateComment = function (array){var z;var k = [];for (var i = 0; i < array.length; i++) {z = Math.floor(Math.random() * array[i].length);if (array[i][z][array.length - 1] == ',') {k.push(array[i][z]);} else {k.push(array[i][z] + ' ');}};return k.join('');};//console.log(generateComment([['hi,', 'hello,', 'hey,'], ['how are'], ['you', 'ya'], ['doing', 'going'], ['?', '?!', '']]));- const generateComment = array => array.map(x=>x[Math.floor(Math.random() * x.length)]).join` `
- // console.log(generateComment([['hi,', 'hello,', 'hey,'], ['how are'], ['you', 'ya'], ['doing', 'going'], ['?', '?!', '']]));