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: Sorted Union | |
// Author: @nirajkrz | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-sorted-union | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
/* Write a function that takes two or more arrays and returns a new array of unique values in the order of the original provided arrays. | |
In other words, all values present from all arrays should be included in their original order, but with no duplicates in the final array. | |
The unique numbers should be sorted by their original order, but the final array should not be sorted in numerical order. */ |
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: Convert HTML Entities | |
// Author: @nirajkrz | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-convert-html-entities | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
/* Convert the characters "&", "<", ">", '"' (double quote), and "'" (apostrophe), in a string to their corresponding HTML entities. */ | |
function convert(str) { | |
// :) | |
// Split by character to avoid problems. |
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: Spinal Tap Case | |
// Author: @nirajkrz | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-spinal-tap-case | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
//Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes. | |
function spinalCase(str) { | |
// "It's such a fine line between stupid, and clever." | |
// --David St. Hubbins | |
// Create a variable for the white space and underscores. |
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: Sum All Odd Fibonacci Numbers | |
// Author: @nirajkrz | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-sum-all-odd-fibonacci-numbers | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
//Return the sum of all odd Fibonacci numbers up to and including the passed number if it is a Fibonacci number. | |
function sumFibs(num) { | |
var prevNumber = 0; | |
var currNumber = 1; | |
var result = 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
// Bonfire: Sum All Primes | |
// Author: @nirajkrz | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-sum-all-primes | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
//Sum all the prime numbers up to and including the provided number. | |
function sumPrimes(num) { | |
var res = 0; | |
// FUnction to get the primes up to max in an 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
// Bonfire: Smallest Common Multiple | |
// Author: @nirajkrz | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-smallest-common-multiple | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function smallestCommons(arr) { | |
arr.sort(function(a, b) { | |
return b - 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
// Bonfire: Finders Keepers | |
// Author: @nirajkrz | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-finders-keepers | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
//Create a function that looks through an array (first argument) and returns the first element in the array that passes a truth test (second argument). | |
function find(arr, func) { | |
var num; |
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: Drop it | |
// Author: @nirajkrz | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-drop-it | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
//Drop the elements of an array (first argument), starting from the front, until the predicate (second argument) returns true. | |
function drop(arr, func) { | |
// Drop them elements. | |
var lol = arr.length; |
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: Steamroller | |
// Author: @nirajkrz | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-steamroller | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
//Flatten a nested array. You must account for varying levels of nesting. | |
function steamroller(arr) { | |
// I'm a steamroller, baby | |
var flattenedArray = []; |
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: Binary Agents | |
// Author: @nirajkrz | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-binary-agents | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
//Return an English translated sentence of the passed binary string. | |
function binaryAgent(str) { |