From 353f002bb234d859b3ee8b5c639f6f3396db7b06 Mon Sep 17 00:00:00 2001 From: KennethJT1 <112853926+KennethJT1@users.noreply.github.com> Date: Wed, 14 Sep 2022 07:03:58 +0100 Subject: [PATCH] Update index.js --- src/list-sorting/index.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/list-sorting/index.js b/src/list-sorting/index.js index 6636c20d..34351bc1 100644 --- a/src/list-sorting/index.js +++ b/src/list-sorting/index.js @@ -1,3 +1,20 @@ -function listSorting(needle, haystack) {} +function listSorting(needle, haystack) { + let rowIndex = haystack.length - 1; + let colIndex = -1; + + for (let i = haystack.length - 1; i >= 0; i--) { + if (Array.isArray(haystack[i])) { + rowIndex = i; + colIndex = haystack[i].lastIndexOf(needle); + if (colIndex != -1) { + return [rowIndex, colIndex]; + } + } else { + if (haystack[i] == needle) return i; + } + } + return -1; +} +console.log(listSorting) module.exports = listSorting;