Skip to content

Instantly share code, notes, and snippets.

View bskydive's full-sized avatar

Valeriy Stepanov bskydive

View GitHub Profile
// Bonfire: Factorialize a Number
// Author: @bskydive
// Challenge: http://www.freecodecamp.com/challenges/bonfire-factorialize-a-number
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function factorialize(num) {
var result=1;
for (i=1;i<=num;i++){
result *=i;
// Bonfire: Check for Palindromes
// Author: @bskydive
// Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function palindrome(str) {
str=str.replace(/[_\W]/gi,'').toLowerCase();
return str===str.split('').reverse().join('');
}
// 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;
}
// 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: 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: 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: 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: 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: 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: 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);
}