diff --git a/src/binary-reversal/index.js b/src/binary-reversal/index.js index 965bccf4..a08c4152 100644 --- a/src/binary-reversal/index.js +++ b/src/binary-reversal/index.js @@ -3,6 +3,11 @@ * * * @param {string} value */ -function binaryReversal(value) {} +function binaryReversal(value) { + return String(parseInt([... + `0000000${Number(value).toString(2)}`.slice(-8) +].reverse().join(""), 2)); + +} module.exports = binaryReversal; diff --git a/src/list-sorting/index.js b/src/list-sorting/index.js index 6636c20d..75487965 100644 --- a/src/list-sorting/index.js +++ b/src/list-sorting/index.js @@ -1,3 +1,45 @@ -function listSorting(needle, haystack) {} +function listSorting(needle, haystack) { + let rowIndex = []; + let colIndex= []; + let index = []; + + if (haystack.length == 0) { + return -1; + } + + for (let i = 0; i < haystack.length; i++) { + if ( + Array.isArray(haystack[i]) === true && + haystack[i].indexOf(needle) > -1 + ) { + rowIndex.push(i); + colIndex.push(haystack[i].lastIndexOf(needle)); + } else { + index.push(haystack.lastIndexOf(needle)); + } + } + + if (rowIndex.length > 1 && colIndex.indexOf(-1) === -1) { + return [ + rowIndex[rowIndex.length - 1], + colIndex[colIndex.length - 1], + ]; + } + if (rowIndex.length === 1 && colIndex.indexOf(-1) === -1) { + return [ + rowIndex[rowIndex.length - 1], + colIndex[colIndex.length - 1], + ]; + } + if ( + rowIndex.length === 0 && + colIndex.length === 0 && + index.length > 0 + ) { + return index[index.length - 1]; + } + + return -1; +} module.exports = listSorting;