diff --git a/src/chapter1/ch1-q6.js b/src/chapter1/ch1-q6.js index 9520b01..612751b 100644 --- a/src/chapter1/ch1-q6.js +++ b/src/chapter1/ch1-q6.js @@ -26,7 +26,7 @@ export function compressString(str) { // JS does not have a StringBuilder/StringBuffer style class for creating strings // string concatenation has been heavily optimised in JS implementations and // is faster than creating a string via an array then using a .join('') at the end - cStr += (i - start + 1) + char; + cStr += char + (i - start + 1); } return cStr.length < str.length ? cStr : str; diff --git a/src/chapter1/ch1-q6.spec.js b/src/chapter1/ch1-q6.spec.js index 925f43a..179bf52 100644 --- a/src/chapter1/ch1-q6.spec.js +++ b/src/chapter1/ch1-q6.spec.js @@ -30,12 +30,12 @@ for (let key in funcs) { }); [ - { arg: 'aaa', out: '3a' }, - { arg: 'bbbbbb', out: '6b' }, - { arg: 'abbbbbbc', out: '1a6b1c' }, - { arg: 'aaabccc', out: '3a1b3c' }, - { arg: 'hhellllllllooooo!', out: '2h1e8l5o1!' }, - { arg: 'woorrrllllddddd', out: '1w2o3r4l5d' } + { arg: 'aaa', out: 'a3' }, + { arg: 'bbbbbb', out: 'b6' }, + { arg: 'abbbbbbc', out: 'a1b6c1' }, + { arg: 'aaabccc', out: 'a3b1c3' }, + { arg: 'hhellllllllooooo!', out: 'h2e1l8o5!1' }, + { arg: 'woorrrllllddddd', out: 'w1o2r3l4d5' } ].forEach(context => { it(`returns ${context.out} with string ${context.arg}`, function() {