This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function binarySearch(arr, findX, leftBound, rightBound) { | |
if(typeof leftBound == 'undefined') { | |
var leftBound = 0, rightBound = arr.length; | |
stepsTaken = 0; | |
} | |
var median = Math.ceil((leftBound + rightBound)/2); | |
console.log("Median Index:", median, "Median Value:", arr[median]); | |
stepsTaken++; | |
if(findX == arr[median]) { | |
console.log("Index of x: ", median) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Find missing number in sorted array | |
//[1, 2, 3, 6] => 5 | |
function findMissingNumber(arr){ | |
var len = arr.length; | |
var totalSum = (len * (len + 1))/2 | |
return totalSum - arr.reduce((acc, curr) => acc + curr, 0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var balancedParanthesis = function (str) { | |
var openParnth = ['[', '{', '('], closedParanth = [']', '}', ')']; | |
var stack = []; | |
for (var i = 0; i < str.length; i++) { | |
if (openParnth.indexOf(str[i]) > -1) { | |
stack.push(str[i]); | |
} | |
if (closedParanth.indexOf(str[i]) > -1) { | |
var lastP = stack.pop(); | |
var lastPIdx = openParnth.indexOf(lastP) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fizzbuzz = num => { | |
var message = ''; | |
if (num % 3 == 0) message += 'fizz'; | |
if (num % 5 == 0) message += 'buzz'; | |
return message; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//HOW to Use: Just paste the below function definition on developer console while you are on Koinex.in | |
// Then call this function on console with Crypto Name like for Bitcoin: showInTitle('BCH') | |
var showInTitle = (function showInTitle() { | |
console.log('Now you can call this function like: showInTitle("BTC");'); | |
var CryptoArray = ['BTC', 'ETH', 'XRP', 'LTC', 'BCH', 'GNT', 'MIOTA', 'OMG']; | |
console.log('Available Cryptos are: ', CryptoArray.join(', ')) | |
return function (cryptoName) { | |
var cryptoIndex = CryptoArray.indexOf(cryptoName); |