--- id: 5a23c84252665b21eecc8036 title: Strip control codes and extended characters from a string challengeType: 5 --- ## Description
The task is to strip control codes and extended characters from a string. In ASCII, the control codes have decimal codes 0 through to 31 and 127. On an ASCII based system, if the control codes are stripped, the resultant string would have all of its characters within the range of 32 to 126 decimal on the ASCII table. On a non-ASCII based system, we consider characters that do not have a corresponding glyph on the ASCII table (within the ASCII range of 32 to 126 decimal) to be an extended character for the purpose of this task.
## Instructions
## Tests
``` yml tests: - text: strip should be a function. testString: assert(typeof strip == 'function', 'strip should be a function.'); - text: strip("abc") should return a string. testString: assert(typeof strip("\ba\\x00b\n\rc\fd\xc3") == 'string', 'strip("abc") should return a string.'); - text: strip("\\ba\\x00b\\n\\rc\\fd\\xc3") should return "abcd". testString: assert.equal(strip("\ba\x00b\n\rc\fd\xc3"), "abcd", 'strip("\\ba\\x00b\\n\\rc\\fd\\xc3") should return "abcd".'); - text: strip("\\u0000\\n abc\\u00E9def\\u007F") should return " abcdef". testString: assert.equal(strip("\u0000\n abc\u00E9def\u007F"), " abcdef", 'strip("\\u0000\\n abc\\u00E9def\\u007F") should return " abcdef".'); - text: strip("a\\n\\tb\\u2102d\\u2147f") should return "abdf". testString: assert.equal(strip("a\n\tb\u2102d\u2147f"), "abdf", 'strip("a\\n\\tb\\u2102d\\u2147f") should return "abdf".'); - text: strip("Français.") should return "Franais.". testString: assert.equal(strip("Français."), "Franais.", 'strip("Français.") should return "Franais.".'); - text: strip("123\\tabc\\u0007DEF\\u007F+-*/€æŧðłþ") should return "123abcDEF+-*/". testString: assert.equal(strip("123\tabc\u0007DEF\u007F+-*/€æŧðłþ"), "123abcDEF+-*/", 'strip("123\\tabc\\u0007DEF\\u007F+-*/€æŧðłþ") should return "123abcDEF+-*/".'); ```
## Challenge Seed
```js function strip(s) { // Good luck! } ```
## Solution
```js function strip(s) { return s.split('').filter(function(x) { var n = x.charCodeAt(0); return 31 < n && 127 > n; }).join(''); } ```