--- id: 5e6dd14797f5ce267c2f19d0 title: Look-and-say sequence challengeType: 5 forumTopicId: 385277 dashedName: look-and-say-sequence --- # --description-- The [Look and say sequence](https://en.wikipedia.org/wiki/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. # --hints-- `lookAndSay` should be a function. ```js assert(typeof lookAndSay == 'function'); ``` `lookAndSay("1")` should return a string. ```js assert(typeof lookAndSay('1') == 'string'); ``` `lookAndSay("1")` should return `"11"`. ```js assert.equal(lookAndSay('1'), '11'); ``` `lookAndSay("11")` should return `"21"`. ```js assert.equal(lookAndSay('11'), '21'); ``` `lookAndSay("21")` should return `"1211"`. ```js assert.equal(lookAndSay('21'), '1211'); ``` `lookAndSay("1211")` should return `"111221"`. ```js assert.equal(lookAndSay('1211'), '111221'); ``` `lookAndSay("3542")` should return `"13151412"`. ```js assert.equal(lookAndSay('3542'), '13151412'); ``` # --seed-- ## --seed-contents-- ```js function lookAndSay(str) { } ``` # --solutions-- ```js function lookAndSay(str) { return str.replace(/(.)\1*/g, function(seq, p1) { return seq.length.toString() + p1; }); } ```