Skip to content

Instantly share code, notes, and snippets.

View elitenomad's full-sized avatar
🎯
Focusing

Pranava S Balugari elitenomad

🎯
Focusing
View GitHub Profile
@elitenomad
elitenomad / joinElements.js
Last active June 20, 2018 10:21
Join elements of an array given a delimiter (Recursive and Regular loop methods)
const joinElements = (array, joiner) => {
const recurse = (index, resultSoFor = '') => {
resultSoFor += array[index];
if (index == array.length - 1) {
return resultSoFor;
} else {
resultSoFor = resultSoFor + joiner;
return recurse(index + 1, resultSoFor);
}
@elitenomad
elitenomad / factorial.js
Created June 20, 2018 10:20
Factorial (Recursive and Regular loop methods)
const factorialWithRecursive = (n) => {
if(n == 1){
return n;
}else{
return (n * factorialWithRecursive(n - 1));
}
}
const factorialRecursive = factorialWithRecursive(5);
console.log(`What is factorialRecursive ${factorialRecursive}`);
@elitenomad
elitenomad / factorialWithMemoization.js
Created June 20, 2018 10:28
factorial with Memoization
const factorialRecursiveWithMemoization = (n) => {
const multiplyer = (ender) => {
if(ender == 1){
return ender;
}else{
return (ender * multiplyer(ender - 1))
}
}
return multiplyer(n);
@elitenomad
elitenomad / binary_search.js
Created June 20, 2018 11:35
Javascript Binary search Implementation
const binary_search = (list, item) => {
let min = 0;
let max = list.length - 1;
let middle_index = Math.floor((min + max)/2);
while(min <= max){
if(list[middle_index] == item) {
return list[middle_index];
}
@elitenomad
elitenomad / bubble_sort.js
Created June 26, 2018 11:53
Bubble sort Javascript implementation: O(n^2)
const bubble_sort = (array) => {
for(let i = 0 ; i < array.length - 1 ; i++) {
for(let j = 0; j < array.length - i - 1; j++){
if(array[j] > array[j + 1]){
const temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}

Keybase proof

I hereby claim:

  • I am elitenomad on github.
  • I am elitenomad (https://keybase.io/elitenomad) on keybase.
  • I have a public key whose fingerprint is 6803 769F 8D8B 79CF F5AE 46F2 5FDA 3049 AFF8 B453

To claim this, I am signing this object:

@elitenomad
elitenomad / remove_duplicates.js
Last active February 21, 2020 00:27
Remove duplicate strings Javascript
function removeDuplicate(str) {
arr = []
prev_value = ''
splitted_str = str.split(' ')
splitted_str.forEach((s) => {
console.log("prev value", prev_value)
console.log("s value", s)
if(s !== prev_value) {
arr.push(s);
@elitenomad
elitenomad / flatten.js
Last active February 21, 2020 01:26
Flatten array of nested arrays Javascript
function flatten(arr) {
a = []
arr.forEach((s) => {
if(Array.isArray(s)){
a = a.concat(flatten(s))
}else{
a.push(s)
}
})
@elitenomad
elitenomad / bind.js
Created February 21, 2020 01:45
implement function.prototype.bind
function.prototype.bind = function(context) {
var fn = this
return function(){
fn.call(context);
}
}
@elitenomad
elitenomad / debounce.js
Created February 21, 2020 02:25
simple implementation of debounce functionality (Type ahead functionality)
function debounce(fn, time) {
let setTimeOutId;
const context = this;
return function() {
if(setTimeoutId) {
clearTimeout(setTimeoutId);
}
setTimeoutId = setTimeout(function(){