random - Generate string with variable words in dynamic places in JavaScript -
i saw skype bots, chat randomized make more human:
{hi|hey|hello}, name bot. {it's|it is} {awesome|dope|cool} meet you! and program replaces {} parts 1 random word ones specified, example:
hi, name bot. it's cool meet you! i thinking how possible, other putting every word array, running through of them searching "{" , "}" , after replacing string, not think else.
you creative , i'm sure there another, better way of doing this.
you can use regex accomplish design:
let s = '{hi|hey|hello}, name bot. {it\'s|it is} {awesome|dope|cool} meet you!'; console.log(s.replace(/\{(.+?)\}/g, (a, v) => { let array = v.split('|'); return array[math.floor(math.random() * array.length))]; });
Comments
Post a Comment