Skip to content
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: 17 additions & 1 deletion src/binary-reversal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
*
* * @param {string} value
*/
function binaryReversal(value) {}
function binaryReversal(value) {
/**
*
*
*
*/
let binaryNum = (parseInt(value).toString(2));
let padding = ("0".repeat(8- binaryNum.length));
binaryNum = padding + binaryNum;
binaryNum = binaryNum.split("").reverse().join("");
binaryNum = parseInt(binaryNum, 2)

return binaryNum.toString();
}


console.log(binaryReversal("10"));

module.exports = binaryReversal;
4 changes: 2 additions & 2 deletions src/list-sorting/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## List Sorting
## List Sorting

You have been given an array of size `N` consisting of integers. In addition you have been given an element `M`. You need to find and print the index of the last occurrence of this element `M` in the array if it exists in it, otherwise print `-1`.

Expand Down Expand Up @@ -28,7 +28,7 @@ needle: 5;
haystack: [
[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5],
];
```

Expand Down
39 changes: 37 additions & 2 deletions src/list-sorting/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
function listSorting(needle, haystack) {}
function listSorting(needle, haystack){
if (typeof (haystack[0]) == "object") {
let lastArray = -1;
let lastIndex;

for (let i = 0; i < haystack.length; i++) {

module.exports = listSorting;
if (haystack[i].includes(needle)) {
lastArray = i;
lastIndex = haystack[i].lastIndexOf(needle)

}
}
if (lastArray != -1) {
return [lastArray, lastIndex]
} else {
return -1
}

}
else {
return haystack.lastIndexOf(needle)
}
}

// console.log(listSorting(5, [1, 2, 3, 4, 5]));

// console.log(listSorting(5, [1, 2, 3, 4, 4, 4]))
// console.log(listSorting(5, [5, 1, 2, 3, 4, 5]))
// console.log(listSorting(0, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]))
// expect(listSorting(-1, [-1, 0, 10, 10, 10, 1, 1, 1, 1, 1, 1])).toBe(0);
// expect(listSorting(2, [2])).toBe(0);
// expect(listSorting(1, [])).toBe(-1);
// expect(listSorting(3, [-1, 0, 1, 2, 3])).toBe(4);
// expect(


module.exports = listSorting;