--- id: 5e6dd14797f5ce267c2f19d0 title: Look-and-say sequence challengeType: 5 forumTopicId: 385277 --- ## Description
The Look and say sequence is a recursively defined sequence of numbers. Sequence Definition This becomes the next number of the sequence. An example:
## Instructions
Write a function that accepts a string as a parameter, processes it, and returns the resultant string.
## Tests
``` yml tests: - text: lookAndSay should be a function. testString: assert(typeof lookAndSay == 'function'); - text: lookAndSay("1") should return a string. testString: assert(typeof lookAndSay("1") == 'string'); - text: lookAndSay("1") should return "11". testString: assert.equal(lookAndSay("1"), "11"); - text: lookAndSay("11") should return "21". testString: assert.equal(lookAndSay("11"), "21"); - text: lookAndSay("21") should return "1211". testString: assert.equal(lookAndSay("21"), "1211"); - text: lookAndSay("1211") should return "111221". testString: assert.equal(lookAndSay("1211"), "111221"); - text: lookAndSay("3542") should return "13151412". testString: assert.equal(lookAndSay("3542"), "13151412"); ```
## Challenge Seed
```js function lookAndSay(str) { } ```
## Solution
```js function lookAndSay(str) { return str.replace(/(.)\1*/g, function(seq, p1) { return seq.length.toString() + p1; }); } ```