Skip to content

Instantly share code, notes, and snippets.

View subodh737's full-sized avatar

Subodh Kumar Sharma subodh737

View GitHub Profile
@subodh737
subodh737 / bonfire-where-art-thou.js
Last active December 4, 2015 22:52
Make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching property and value pairs (second argument). Each property and value pair of the source object has to be present in the object from the collection if it is to be included in the returned array. For example, if the first a…
// Bonfire: Where art thou
// Author: @subodh737
// Challenge: http://www.freecodecamp.com/challenges/bonfire-where-art-thou
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function where(collection, source) {
// "What's in a name? that which we call a rose
// By any other name would smell as sweet.”
// -- by William Shakespeare, Romeo and Juliet
var srcKeys = Object.keys(source);
// Bonfire: Where do I belong
// Author: @subodh737
// Challenge: http://www.freecodecamp.com/challenges/bonfire-where-do-i-belong
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function where(arr, num) {
// Find my place in this sorted array.
arr.push(num);
arr.sort(function(a, b) { return a - b; });
return arr.indexOf(num);
// Bonfire: Seek and Destroy
// Author: @subodh737
// Challenge: http://www.freecodecamp.com/challenges/bonfire-seek-and-destroy
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function destroyer(arr) {
// Remove all the values
var arrFiltered = [];
var args = Array.prototype.slice.call(arguments, 1);
arrFiltered = arr.filter(function(val) {
// Bonfire: Falsy Bouncer
// Author: @subodh737
// Challenge: http://www.freecodecamp.com/challenges/bonfire-falsy-bouncer
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function bouncer(arr) {
// Don't show a false ID to this bouncer.
var arrFiltered = arr.filter(function(val) {
return Boolean(val);
});
// Bonfire: Mutations
// Author: @subodh737
// Challenge: http://www.freecodecamp.com/challenges/bonfire-mutations
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function mutation(arr) {
//-- Both elements to different vars
var str1 = arr[0].toLowerCase();
var str2 = arr[1].toLowerCase();
//-- Split & sort the chars
// Bonfire: Slasher Flick
// Author: @subodh737
// Challenge: http://www.freecodecamp.com/challenges/bonfire-slasher-flick
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function slasher(arr, howMany) {
// it doesn't always pay to be first
arr = arr.slice(howMany);
//console.log(arr);
return arr;
// Bonfire: Chunky Monkey
// Author: @subodh737
// Challenge: http://www.freecodecamp.com/challenges/bonfire-chunky-monkey
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function chunk(arr, size) {
// Break it up.
var arrTemp = [];
while (arr.length > 0) {
arrTemp.push(arr.splice(0, size));
// Bonfire: Truncate a string
// Author: @subodh737
// Challenge: http://www.freecodecamp.com/challenges/bonfire-truncate-a-string
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function truncate(str, num) {
// Clear out that junk in your trunk
if (str.length > num) {
if (num > 3) {
str = str.slice(0, (num - 3));
// Bonfire: Repeat a string repeat a string
// Author: @subodh737
// Challenge: http://www.freecodecamp.com/challenges/bonfire-repeat-a-string-repeat-a-string
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function repeat(str, num) {
// repeat after me
var strTemp = "";
if (num < 0) {
return "";
// Bonfire: Confirm the Ending
// Author: @subodh737
// Challenge: http://www.freecodecamp.com/challenges/bonfire-confirm-the-ending
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function end(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
var strTemp;
//--