Skip to content

Instantly share code, notes, and snippets.

View Narshe1412's full-sized avatar
📚
On my way to something great!

Manuel Narshe1412

📚
On my way to something great!
View GitHub Profile
// Bonfire: Repeat a string repeat a string
// Author: @narshe1412
// 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
if (num < 0) {return "";}
var result ="";
for (var i=0; i<num; i++){
// Bonfire: Title Case a Sentence
// Author: @narshe1412
// 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 strtemp = str.toLowerCase().split(" ");
for (var i = 0; i < strtemp.length; i++){
var firstLetter = strtemp[i].charAt(0).toUpperCase();
strtemp[i] = firstLetter + strtemp[i].substring(1);
// Bonfire: Find the Longest Word in a String
// Author: @narshe1412
// 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 strArray = str.split(" ");
var biggestWord = 0;
for (var i=0; i<strArray.length; i++){
if (strArray[i].length > biggestWord) {
// Bonfire: Truncate a string
// Author: @narshe1412
// 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
var result = "";
if (num <= 3) {
result = str.slice(0,num) + "...";
// Bonfire: Meet Bonfire
// Author: @narshe1412
// Challenge: http://www.freecodecamp.com/challenges/bonfire-meet-bonfire
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function meetBonfire(argument) {
// Good luck!
console.log("you can read this function's argument in the developer tools", argument);
return true;
// Bonfire: Reverse a String
// Author: @narshe1412
// Challenge: http://www.freecodecamp.com/challenges/bonfire-reverse-a-string
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function reverseString(str) {
/*var myArr = str.split("");
var reversedArr = myArr.reverse();
var reversedStr = reversedArr.join("");
return reversedStr;*/
// Bonfire: Factorialize a Number
// Author: @narshe1412
// Challenge: http://www.freecodecamp.com/challenges/bonfire-factorialize-a-number
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function factorialize(num) {
var total = 1;
for (var i = 0; i < num; i++){
total *= i+1;
}
// Bonfire: Check for Palindromes
// Author: @narshe1412
// Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function palindrome(str) {
// Good luck!
return str.toLowerCase().replace(/[\W_]/g,'') === str.split("").reverse().join("").toLowerCase().replace(/[\W_]/g,'');
}
// Bonfire: Return Largest Numbers in Arrays
// Author: @narshe1412
// 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) {
// You can do this!
var result = [];
for (var i=0; i<4; i++){
var max = arr[i][0];
// Bonfire: Confirm the Ending
// Author: @narshe1412
// 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
return str.substr(str.length-target.length) === target;
}