From ce7cc2f933cf3c045e3f8747b4ce52a71d2c0be5 Mon Sep 17 00:00:00 2001 From: Yauheni Zhdan Date: Fri, 24 Mar 2017 00:29:02 -0700 Subject: [PATCH] =?UTF-8?q?Update=20ch1-q6=20according=20to=20task=20descr?= =?UTF-8?q?iption:=20'...=20=D0=B0=D0=B0b=D1=81=D1=81=D1=81=D1=81=D1=81?= =?UTF-8?q?=D0=B0=D0=B0=D0=B0=20transforms=20to=20=D0=B02b1=D1=815=D0=B03?= =?UTF-8?q?=20...'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chapter1/ch1-q6.js | 2 +- src/chapter1/ch1-q6.spec.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) 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() {