loading...

re: Daily Challenge #115 - Look and Say Sequence VIEW POST

FULL DISCUSSION
 

Here's a one line solution in javascript.

Zero readability, maximum coolness. 😎

const lookAndSaySequence = (text, count) => count <= 1 ? text : lookAndSaySequence(text.match(/(.)\1*/g).map(frag => `${frag.length}${frag[0]}`).join(''), count - 1);

console.log(lookAndSaySequence('1', 1));    // 1
console.log(lookAndSaySequence('1', 3));    // 21
console.log(lookAndSaySequence('1', 5));    // 111221
console.log(lookAndSaySequence('22', 10));  // 22
console.log(lookAndSaySequence('14', 2));   // 1114
code of conduct - report abuse