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
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"githubPullRequests.ignoredPullRequestBranches": [
"master"
]
}
13 changes: 12 additions & 1 deletion src/binary-reversal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
*
* * @param {string} value
*/
function binaryReversal(value) {}
function binaryReversal(value) {

let t = value.toString(2).split("");
let str_len = t.length;
for (let i = 0; i < 8 - str_len; i++) {
t.unshift("0");
}
return parseInt(t.reverse().join(""), 2);
}
// 14 -> 00001110 -> 01110000 -> 112
console.log(binaryReversal(121));


module.exports = binaryReversal;
32 changes: 30 additions & 2 deletions src/list-sorting/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
function listSorting(needle, haystack) {}
/**
* @param {string} haystack
* @param {string} needle
* @return {number}
*/
function listSorting(haystack, needle) {
if (!needle.length) return 0;

module.exports = listSorting;
// Loop through the haystack's letters
for (let i = 0; i <= haystack.length - needle.length; i++) {
// Check if the current letter matches the start of the needle
if (haystack[i] === needle[0]) {
// Loop through the needle
for (let j = 0; ; j++) {
// Reached the end of the needle (and thus fully found it at i)
if (j == needle.length) {
return i;
}
// Letters not matched (needle not found at i)
else if (haystack[i + j] !== needle[j]) {
break;
}
}
}
}
return haystack;
}

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

module.exports = listSorting;