Skip to content

Added new algorithm #19

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

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
28 changes: 28 additions & 0 deletions ConvertBinaryToString/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function binaryAgent(str) {
let bytes = str.split(' ');
let output = '';

for (let k = 0; k < bytes.length; k++){
output += String.fromCharCode(convertToDecimal(bytes[k]));
}

return output;
}

function convertToDecimal(byte) {
let result = 0;

byte = byte.split('');

byte.reverse();

for (let a = 0; a < byte.length; a++){
if (byte[a] === '1'){
result += 2 ** a;
}
}

return result;
}

binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
18 changes: 18 additions & 0 deletions JSAlgorithms/algorithms_IS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function insertionSort(unsortedList) {
var len = unsortedList.length;
for (var i = 1; i < len; i++) {
var tmp = unsortedList[i]; //Copy of the current element.
/*Check through the sorted part and compare with the number in tmp. If large, shift the number*/
for (var j = i - 1; j >= 0 && (unsortedList[j] > tmp); j--) {
//Shift the number
unsortedList[j + 1] = unsortedList[j];
}
//Insert the copied number at the correct position
//in sorted part.
unsortedList[j + 1] = tmp;
}
}

var ul = [5, 3, 1, 2, 4];
insertionSort(ul);
console.log(ul);