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
14 changes: 13 additions & 1 deletion 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) {}
function binaryReversal(value) {
//convert to binary
let bin= (parseInt(value).toString(2));
//create a string of 0* padding length
let pad= ("0".repeat(8- bin.length));
bin= pad + bin;
//reverse string
bin= bin.split("").reverse().join("");
//convert back to binary
bin = parseInt(bin, 2)
// convert back to string
return bin.toString();
}

module.exports = binaryReversal;
35 changes: 34 additions & 1 deletion src/list-sorting/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
function listSorting(needle, haystack) {}
function listSorting(needle, haystack) {
//check if haystack is an array of arrays
if(typeof(haystack[0])=="object"){
let lastArray=-1;
let lastIndex;
for (let i=0; i<haystack.length; i++){

if (haystack[i].includes(needle)){
//keep making lastArray = index of haystack that includes needle until loop completes
lastArray= i;
//keep making lastIndex = index of needle in haystack of i until loop completes
lastIndex= haystack[i].lastIndexOf(needle);
}
}
//check is lastarray has not been modified in the if statement
if(lastArray!= -1){
return [lastArray, lastIndex]
}
else{
return -1;
}
}
//condition for typeof haystack[0] != array
else{
if(haystack.includes(needle)){
return haystack.lastIndexOf(needle);
}
else{
return -1;
}

}
//
}

module.exports = listSorting;