Skip to content

Instantly share code, notes, and snippets.

View BeKnowDo's full-sized avatar
:bowtie:
Focusing

Cesar Perez BeKnowDo

:bowtie:
Focusing
View GitHub Profile
@BeKnowDo
BeKnowDo / remove-vowels.js
Created June 12, 2017 18:40
Remove Vowels from string
function disemvowel(str) {
return str.replace(/[aeiouy]/ig,'').toString();
}
console.log(disemvowel('This website is for losers LOL!'))
@BeKnowDo
BeKnowDo / digital-root.js
Created June 12, 2017 18:39
Digital Root
function digitalRoot(number) {
let lengthCheck = ''
const originalNumber = number
function add(a, b) {
this.a = parseInt(a)
this.b = parseInt(b)
return this.a + this.b
}
@BeKnowDo
BeKnowDo / kadane-algorithm.js
Created June 12, 2017 18:39
Kadane's Algorithm
var maxSequence = function(array) {
let currentMax = max = 0
array.map(function(item, index){
// make sure current is greater than zero
currentMax = Math.max(0, currentMax + array[index])
// replace max with current max if greater
max = Math.max(max, currentMax)
@BeKnowDo
BeKnowDo / sequence-classifier.js
Created June 12, 2017 18:39
Sequence Classifier
sequenceClassifier = (arr) => {
let classifier = null,
strictlyIncreased = 1,
strictlyDecreased = 1,
constant = 1,
hasDecreased = false,
hasIncreased = false
arr.map(function(item, index) {
@BeKnowDo
BeKnowDo / equilibrium-index.js
Created June 12, 2017 18:38
Equilibrium Index
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
let sum = null,
previous_sum = 0,
next_sum = null;
if(!A || A.length === 0) {
return -1;
@BeKnowDo
BeKnowDo / binary-gaps.js
Created June 12, 2017 18:38
Binary Gaps
const binaryGaps = (number) => {
let binaryConversion = number.toString(2);
binaryConversion
return binaryConversion;
}
@BeKnowDo
BeKnowDo / bubble-sort.js
Created June 12, 2017 18:38
Bubble Sort
const BubbleSort = (values) => {
let originalValues = values.slice(),
length = originalValues.length - 1,
swapped;
do {
swapped = false;
values.forEach((item, index, values) => {
let currentItem = values[index],
@BeKnowDo
BeKnowDo / array-min-max.js
Created June 12, 2017 18:37
Min/Max of Array
const Min = (array) => {
const min = Math.min(...array);
return min;
}
const Max = (array) => {
const max = Math.max(...array);
return max;
}
@BeKnowDo
BeKnowDo / contiguous-groups.js
Created June 12, 2017 18:16
Contiguous Groups
const ContiguousGroups = (array) => {
const arrayValues = array.sort();
let contiguousCount = 0,
foundMatch = false;
arrayValues.map(function(item, index) {
let findDifference = Math.abs(item - arrayValues[index + 1]);
if (!isNaN(findDifference) && findDifference === 0) {
@BeKnowDo
BeKnowDo / wordmachine.js
Created June 12, 2017 18:15
Wordmachine
const wordMachine = (commands) => {
const operations = commands.split(' ');
let stack = [];
commandCount = 0;
operations.map((item, index) => {
let detectInteger = parseInt(item);
commandCount++;
//console.log(stack);