Skip to content

Instantly share code, notes, and snippets.

View bskydive's full-sized avatar

Valeriy Stepanov bskydive

View GitHub Profile
// Bonfire: Falsy Bouncer
// Author: @bskydive
// Challenge: http://www.freecodecamp.com/challenges/bonfire-falsy-bouncer#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function bouncer(arr) {
function filtMe(value){
var result=false;
//NaN,undefined,null check only this way
// Bonfire: Mutations
// Author: @bskydive
// Challenge: http://www.freecodecamp.com/challenges/bonfire-mutations#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function mutation(arr) {
var result=true;
var i=0;
var arr1ToLower = arr[0].toLowerCase();
var arr2ToLower = arr[1].toLowerCase().split('');
// Bonfire: Slasher Flick
// Author: @bskydive
// Challenge: http://www.freecodecamp.com/challenges/bonfire-slasher-flick#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function slasher(arr, howMany) {
return arr.slice(howMany,arr.length);
}
// Bonfire: Chunky Monkey
// Author: @bskydive
// Challenge: http://www.freecodecamp.com/challenges/bonfire-chunky-monkey#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function chunk(arr, size) {
var subArr=[];
for (var i=0;i<arr.length;i=i+size){
subArr.push(arr.slice(i,i+size));
// Bonfire: Truncate a string
// Author: @bskydive
// Challenge: http://www.freecodecamp.com/challenges/bonfire-truncate-a-string#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function truncate(str, num) {
return num>=str.length?str:str.substr(0,num-(num>=3?3:0))+'...';
}
// Bonfire: Repeat a string repeat a string
// Author: @bskydive
// 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
return num<=0?'':str.repeat(num);
}
// Bonfire: Confirm the Ending
// Author: @bskydive
// Challenge: http://www.freecodecamp.com/challenges/bonfire-confirm-the-ending#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function end(str, target) {
return str.substr(-target.length,target.length)==target;
}
// Bonfire: Return Largest Numbers in Arrays
// Author: @bskydive
// Challenge: http://www.freecodecamp.com/challenges/bonfire-return-largest-numbers-in-arrays#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function largestOfFour(arr) {
return arr.map(function (varArr){
return varArr.reduce(function(a,b){
return a>b?a:b;
// Bonfire: Title Case a Sentence
// Author: @bskydive
// Challenge: http://www.freecodecamp.com/challenges/bonfire-title-case-a-sentence#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function titleCase(str) {
var strToMasUpperCased=str.split(' ').map(
function (val){
val=val.toLowerCase();
// Bonfire: Find the Longest Word in a String
// Author: @bskydive
// Challenge: http://www.freecodecamp.com/challenges/bonfire-find-the-longest-word-in-a-string#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function findLongestWord(str) {
var strToMasSorted=str.split(' ').sort(function compare(a,b){return a.length-b.length;});
return strToMasSorted[strToMasSorted.length-1].length;
}