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;