Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angelachallenge3 #129

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/binary-reversal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
*
* * @param {string} value
*/
function binaryReversal(value) {}

module.exports = binaryReversal;
function binaryReversal(value) {
// conversion of integar to binary
let toBinary = parseInt(value).toString(2);
// padding of the binary to 8 bits.
let padBinary = toBinary.padStart(8,0);
// split the padded binary,reverse and join.
let reversedBinary = padBinary.split('').reverse().join('')
// convert the reversed binary into digits and store in a variable finalNum
let finalNum = parseInt(reversedBinary, 2);
// return the final result
return `${finalNum}`

}
module.exports = binaryReversal;

22 changes: 19 additions & 3 deletions src/list-sorting/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
function listSorting(needle, haystack) {}

module.exports = listSorting;
function listSorting(needle, haystack) {
// if haystack is not a single array, return last index of haystack(needle).
if(!Array.isArray(haystack[0])){
return haystack.lastIndexOf(needle)
}
// loop through the haystack row using for loop in descending order
// loop through the haystack column to identify the last index(needle)
// if the last index of the colum exists, return row, column, else return -1.
for (let row = haystack.length-1; row >= 0; row--){
let col = haystack[row].lastIndexOf(needle)
if (col !==-1){
return [row, col]
}
}
return -1
}

module.exports = listSorting;