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 drop(arr, func) { | |
// Drop them elements. | |
while (!func(arr[0])) { // Check if the first one gets false when passed as value to the function | |
arr.shift(); // Drops it, making the second to become the first value now | |
} | |
return arr; //Return what's left on the array. | |
} |
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 find(arr, func) { | |
var solution; | |
solution = arr.filter(func); | |
return solution[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
function smallestCommons(arr) { | |
// Greates common divisor formula | |
function gcd(a, b) { | |
while (b !== 0) { | |
var t = b; | |
b = a % b; | |
a = t; | |
} | |
return a; | |
} |
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 sumFibs(num) { | |
//Fibonacci(n) = Fibonacci (n-1) + Fibonacci (n-2) | |
if (num === 0) return 0; | |
if (num === 1) return 1; | |
var result = 0, | |
prevValue = 0, | |
currentValue = 1; | |
/*for (var i=0; i<=num; i++) { | |
}*/ |
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 spinalCase(str) { | |
// "It's such a fine line between stupid, and clever." | |
// --David St. Hubbins | |
var returnedStr = str.replace(/([a-z])([A-Z])/g, "$1 $2") //converting camelCase into camel Case so in can be affected by next replace() | |
.replace(/\s+/g,"-") //splitting spaces | |
.replace(/_+/g, "-"); //splitting underscores | |
return returnedStr.toLowerCase(); | |
} |
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 convert(str) { | |
// :) | |
var regex = /<|>|&|"|'/g; | |
var convertedStr = str.replace(regex, function (x){ | |
switch (x) { | |
case '<': | |
return "<"; | |
case '>': | |
return ">"; | |
case '&': |
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 fearNotLetter(str) { | |
for (var i = 0, char = str.charCodeAt(0); i < str.length; i++, char++) { | |
if (str.charCodeAt(i) !== char) { | |
return String.fromCharCode(char); | |
} | |
} | |
} | |
fearNotLetter("abce"); |
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 translate(str) { | |
var vocal = ["a", "e", "i", "o", "u"]; | |
var solution = ""; | |
var cutLoc = 0; | |
for (var i = 0 ; i < str.length; i++){ | |
for (var vowel in vocal) { | |
if (vocal.indexOf(str.charAt(i)) >= 0) { | |
if (i === 0) { | |
return str + "way"; | |
} else { |
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
// Bonfire: Roman Numeral Converter | |
// Author: @narshe1412 | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-roman-numeral-converter | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function convert(number) { | |
if ((number < 0) || (number > 3999)) {alert("Please select a number between 1 and 3999");} | |
if (number >= 1000) return "M" + convert(number - 1000); | |
if (number >= 900) return "CM" + convert(number - 900); | |
if (number >= 500) return "D" + convert(number - 500); |
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
// Bonfire: Diff Two Arrays | |
// Author: @narshe1412 | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-diff-two-arrays | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function diff(arr1, arr2) { | |
var newArr = []; | |
// Same, same; but different. | |
for (i=0; i < arr1.length; i++){ | |
if (arr2.indexOf(arr1[i]) < 0){ |