Skip to content

Instantly share code, notes, and snippets.

View Narshe1412's full-sized avatar
📚
On my way to something great!

Manuel Narshe1412

📚
On my way to something great!
View GitHub Profile
@Narshe1412
Narshe1412 / Drop it.js
Last active December 17, 2015 19:28
http://www.freecodecamp.com/narshe1412 's solution for Bonfire: Drop It
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.
}
@Narshe1412
Narshe1412 / Finders Keepers.js
Created December 17, 2015 18:56
http://www.freecodecamp.com/narshe1412 's solution for Bonfire: Finders Keepers
function find(arr, func) {
var solution;
solution = arr.filter(func);
return solution[0];
}
@Narshe1412
Narshe1412 / Smallest Common Multiple.js
Created December 17, 2015 18:17
http://www.freecodecamp.com/narshe1412 's solution for Bonfire:Smallest Common Multiple
function smallestCommons(arr) {
// Greates common divisor formula
function gcd(a, b) {
while (b !== 0) {
var t = b;
b = a % b;
a = t;
}
return a;
}
@Narshe1412
Narshe1412 / Odd Fibonacci.js
Created December 16, 2015 17:44
http://www.freecodecamp.com/narshe1412 's solution for Bonfire:Sum All Odd Fibonacci Numbers
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++) {
}*/
@Narshe1412
Narshe1412 / Spinal Case regex.js
Created December 16, 2015 17:01
http://www.freecodecamp.com/narshe1412 's solution for Bonfire:Spinal Tap Case
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();
}
@Narshe1412
Narshe1412 / Bonfire Convert HTML.js
Created December 16, 2015 16:20
http://www.freecodecamp.com/narshe1412 's solution for Bonfire:Convert HTML Entities
function convert(str) {
// &colon;&rpar;
var regex = /<|>|&|"|'/g;
var convertedStr = str.replace(regex, function (x){
switch (x) {
case '<':
return "&lt;";
case '>':
return "&gt;";
case '&':
@Narshe1412
Narshe1412 / Bonfire Missing Letters.js
Last active December 16, 2015 11:53
http://www.freecodecamp.com/narshe1412 's solution for Bonfire: Missing Letters
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");
@Narshe1412
Narshe1412 / bonfire Pig latin.js
Last active December 16, 2015 11:51
http://www.freecodecamp.com/narshe1412 's solution for Bonfire: Pig Latin
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 {
// 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);
// 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){