From f1ea0a5542c8be3bffdde4c9455b0900d2f704ad Mon Sep 17 00:00:00 2001 From: yayuyokitano <69117606+yayuyokitano@users.noreply.github.com> Date: Tue, 24 Nov 2020 12:35:15 +0800 Subject: [PATCH] Code improvements --- src/classes/helper.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/classes/helper.ts b/src/classes/helper.ts index ab20ae6a..4674a26c 100644 --- a/src/classes/helper.ts +++ b/src/classes/helper.ts @@ -208,7 +208,7 @@ export default class HelperClass { let request = [ this.lastfm.user.getTopArtists(user1, {limit, period}), this.lastfm.user.getTopArtists(user2, {limit, period}) - ] + ]; const res = await Promise.all(request); @@ -262,7 +262,10 @@ export default class HelperClass { let common = []; while (i1 < aSort.length && i2 < bSort.length) { - if (aSort[i1].name.localeCompare(bSort[i2].name) === 0) { + + const compare = aSort[i1].name.localeCompare(bSort[i2].name); + + if (compare === 0) { common.push({ name: aSort[i1].name, url: aSort[i1].url, @@ -270,10 +273,9 @@ export default class HelperClass { }); i1++; i2++; - } else if (aSort[i1].name.localeCompare(bSort[i2].name) < 0) { - i1++; } else { - i2++; + i1 += +(compare < 0); + i2 += +(compare > 0); } } return common;