From e5f574e10c38d163d87c3e4cf057fa1d22324cae Mon Sep 17 00:00:00 2001 From: Kieran Boyle Date: Tue, 13 Apr 2021 10:28:50 -0700 Subject: [PATCH] minor refactor to .eq logic --- demo/index.html | 2 +- src/methods.js | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/demo/index.html b/demo/index.html index 49ddb46..3cd9fa9 100644 --- a/demo/index.html +++ b/demo/index.html @@ -292,7 +292,7 @@ recusandae suscipit repellendus placeat necessitatibus blanditiis aspernatur! Debitis voluptas officiis, voluptate, mollitia dolore distinctio! Sed.

- + diff --git a/src/methods.js b/src/methods.js index 89657fc..c3ac08c 100644 --- a/src/methods.js +++ b/src/methods.js @@ -562,19 +562,12 @@ function index() { } return undefined; } + function eq(index) { - if (typeof index === 'undefined') return this; - const length = this.length; - if (index > length - 1) { - return $([]); - } - if (index < 0) { - const returnIndex = length + index; - if (returnIndex < 0) return $([]); - return $([this[returnIndex]]); - } - return $([this[index]]); + if (index === undefined) return this; + return $(index < 0 ? this[index += this.length] : this[index]); } + function append(...els) { let newChild; const document = getDocument();