From 46b6b2975530e2de9f3dcaa265f473ec55be2458 Mon Sep 17 00:00:00 2001 From: toastal Date: Sat, 10 Mar 2018 11:14:55 +0700 Subject: [PATCH] Using `reduce` to remove extra iterations (#2122) * Using `reduce` to not iterate so much * Remove the Array.from as well --- src/drivers/npm/driver.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/drivers/npm/driver.js b/src/drivers/npm/driver.js index 7b66838a1..d0a593bc0 100644 --- a/src/drivers/npm/driver.js +++ b/src/drivers/npm/driver.js @@ -133,11 +133,17 @@ class Driver { js }) .then(() => { - const links = Array.from(browser.document.getElementsByTagName('a')) - .filter(link => link.protocol === 'http:' || link.protocol === 'https:') - .filter(link => link.hostname === this.origPageUrl.hostname) - .filter(link => extensions.test(link.pathname)) - .map(link => { link.hash = ''; return url.parse(link.href) }); + const links = Array.prototype.reduce.call( + browser.document.getElementsByTagName('a'), + (acc, link) => { + if (link.protocol.match(/https?:/) || link.hostname === this.origPageUrl.hostname || extensions.test(link.pathname)) { + link.hash = ''; + acc.push(url.parse(link.href)); + } + return acc; + }, + [] + ); return resolve(links); });