From ceeac18e6ddb9b605cf9ff9f3bd9071dcbcb0068 Mon Sep 17 00:00:00 2001 From: XaveScor Date: Mon, 3 Aug 2020 15:45:48 +0300 Subject: [PATCH 1/4] early return for strings and numbers --- src/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index abce2aa..a0a0a6d 100644 --- a/src/index.js +++ b/src/index.js @@ -2,8 +2,10 @@ function toVal(mix) { var k, y, str=''; if (typeof mix === 'string' || typeof mix === 'number') { - str += mix; - } else if (typeof mix === 'object') { + return mix; + } + + if (typeof mix === 'object') { if (Array.isArray(mix)) { for (k=0; k < mix.length; k++) { if (mix[k]) { From 2475c443c4866a07a25b3a914dd452cd25f0e8e1 Mon Sep 17 00:00:00 2001 From: XaveScor Date: Mon, 3 Aug 2020 15:46:53 +0300 Subject: [PATCH 2/4] rename variable for increase concat pattern --- src/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index a0a0a6d..accb9c0 100644 --- a/src/index.js +++ b/src/index.js @@ -7,18 +7,18 @@ function toVal(mix) { if (typeof mix === 'object') { if (Array.isArray(mix)) { - for (k=0; k < mix.length; k++) { - if (mix[k]) { - if (y = toVal(mix[k])) { + for (y=0; y < mix.length; y++) { + if (mix[y]) { + if (k = toVal(mix[y])) { str && (str += ' '); - str += y; + str += k; } } } } else { for (k in mix) { if (mix[k]) { - str && (str += ' '); + str && (str += " "); str += k; } } From 064a2e5978c730d75071da24519dcf28999f1c81 Mon Sep 17 00:00:00 2001 From: XaveScor Date: Mon, 3 Aug 2020 15:58:17 +0300 Subject: [PATCH 3/4] fix codestyle --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index accb9c0..9bc6fe8 100644 --- a/src/index.js +++ b/src/index.js @@ -18,7 +18,7 @@ function toVal(mix) { } else { for (k in mix) { if (mix[k]) { - str && (str += " "); + str && (str += ' '); str += k; } } From 35deeaa04482659c5c757ea218a8e6e7ed8ccefd Mon Sep 17 00:00:00 2001 From: XaveScor Date: Tue, 4 Aug 2020 11:12:11 +0300 Subject: [PATCH 4/4] chore: added tests for number case --- test/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/index.js b/test/index.js index b4e6b2f..3b67335 100644 --- a/test/index.js +++ b/test/index.js @@ -15,6 +15,11 @@ test('strings', t => { t.end(); }); +test('numbers', t => { + t.equal(fn(123, 456), '123 456'); + t.end(); +}); + test('strings (variadic)', t => { t.is(fn(''), ''); t.is(fn('foo'), 'foo');