Skip to content

Instantly share code, notes, and snippets.

View Rahul-Sagore's full-sized avatar
:shipit:
Ship it!

Rahul Sagore Rahul-Sagore

:shipit:
Ship it!
View GitHub Profile
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)
// 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);
}
@Rahul-Sagore
Rahul-Sagore / balancedParanthesis.js
Last active June 9, 2018 22:15
Program to examine whether the pairs and the orders of “{“,”}”,”(“,”)”,”[“,”]” are correct in expression.
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)
@Rahul-Sagore
Rahul-Sagore / fizzbuzz.js
Last active April 1, 2018 13:29
Fizzbuzz output function in Javascript
var fizzbuzz = num => {
var message = '';
if (num % 3 == 0) message += 'fizz';
if (num % 5 == 0) message += 'buzz';
return message;
}
@Rahul-Sagore
Rahul-Sagore / changeKoinexTitleBar.js
Last active December 31, 2017 01:18
Change the Koinex.in title Bar to display Current Value of Cryptocurrencies.
//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);