diff --git a/src/binary-reversal/index.js b/src/binary-reversal/index.js index 965bccf4..cf2fc9ca 100644 --- a/src/binary-reversal/index.js +++ b/src/binary-reversal/index.js @@ -3,6 +3,26 @@ * * * @param {string} value */ -function binaryReversal(value) {} +/*My thought process: +- remove the string by converting the value to integar; +- convert to binary usingthe toString method; +- pad the binary num to 8 bits; +- reverse the binary num; +- convert the binary num to a decimal num, as well convert the num to string; +- then return the decimal num; +*/ + +function binaryReversal(value) { + let toIntegar = parseInt(value); + let toBinary = toIntegar.toString(2); + + let paddedNum = toBinary.padStart(8, 0); + let reversedNum = paddedNum.split("").reverse().join(""); + + let decimalNum = parseInt(reversedNum, 2).toString(); + return decimalNum; +}; + + module.exports = binaryReversal; diff --git a/src/list-sorting/index.js b/src/list-sorting/index.js index 6636c20d..9466bf9f 100644 --- a/src/list-sorting/index.js +++ b/src/list-sorting/index.js @@ -1,3 +1,21 @@ -function listSorting(needle, haystack) {} +/*My thought process: +- remove the string by converting the value to integar; +- convert to binary usingthe toString method; +- pad the binary num to 8 bits; +- reverse the binary num; +- convert the binary num to a decimal num, as well convert the num to string; +- then return the decimal num; +*/ + +function binaryReversal(value) { + let toIntegar = parseInt(value); + let toBinary = toIntegar.toString(2); + + let paddedNum = toBinary.padStart(8, 0); + let reversedNum = paddedNum.split("").reverse().join(""); + + let decimalNum = parseInt(reversedNum, 2).toString(); + return decimalNum; +}; module.exports = listSorting;