Skip to content

Instantly share code, notes, and snippets.

View nirajkrz's full-sized avatar

ncode nirajkrz

View GitHub Profile
// 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.
// 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) {
// &colon;&rpar;
// Split by character to avoid problems.
// 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. */
// Bonfire: Boo who
// Author: @nirajkrz
// Challenge: http://www.freecodecamp.com/challenges/bonfire-boo-who
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function boo(bool) {
// What is the new fad diet for ghost developers? The Boolean.
//Check if a value is classified as a boolean primitive. Return true or false.
return typeof bool === 'boolean';
// Bonfire: Missing letters
// Author: @nirajkrz
// Challenge: http://www.freecodecamp.com/challenges/bonfire-missing-letters
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function fearNotLetter(str) {
// Create our variables.
var firstCharacter = str.charCodeAt(0);
var valueToReturn = '';
var secondCharacter = '';
// Bonfire: DNA Pairing
// Author: @nirajkrz
// Challenge: http://www.freecodecamp.com/challenges/bonfire-dna-pairing
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function pair(str) {
/*The DNA strand is missing the pairing element. Take each character, get its pair, and return the results as a 2d array.
Base pairs are a pair of AT and CG. Match the missing element to the provided character.
// Bonfire: Pig Latin
// Author: @nirajkrz
// Challenge: http://www.freecodecamp.com/challenges/bonfire-pig-latin
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function translate(str) {
// Create variables to be used
var pigLatin = '';
var regex = /[aeiou]/gi;
// Check if the first character is a vowel
// Bonfire: Search and Replace
// Author: @nirajkrz
// Challenge: http://www.freecodecamp.com/challenges/bonfire-search-and-replace
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function myReplace(str, before, after) {
// Find index where before is on string
var index = str.indexOf(before);
// Check to see if the first letter is uppercase or not
if (str[index] === str[index].toUpperCase()) {
// Bonfire: Where art thou
// Author: @nirajkrz
// Challenge: http://www.freecodecamp.com/challenges/bonfire-where-art-thou
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function where(collection, source) {
var arr = [];
// What's in a name?
var keys = Object.keys(source);
// Filter array and remove the ones that do not have the keys from source.
// Bonfire: Roman Numeral Converter
// Author: @nirajkrz
// Challenge: http://www.freecodecamp.com/challenges/bonfire-roman-numeral-converter
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function convert(num) {
if (!+num)
return false;
var digits = String(+num).split(""),
key = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM",