diff --git a/ConvertBinaryToString/index.js b/ConvertBinaryToString/index.js new file mode 100644 index 0000000..ed92eca --- /dev/null +++ b/ConvertBinaryToString/index.js @@ -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"); diff --git a/JSAlgorithms/algorithms_IS.js b/JSAlgorithms/algorithms_IS.js new file mode 100644 index 0000000..b00c01a --- /dev/null +++ b/JSAlgorithms/algorithms_IS.js @@ -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); \ No newline at end of file