Skip to content

Instantly share code, notes, and snippets.

View AdrianSkar's full-sized avatar
:octocat:

Adrian Skar AdrianSkar

:octocat:
View GitHub Profile
function titleCase(str) {
var a = str.split(' '), word=[]; //Split input and create new array var
for (i=a.length-1; i>=0; i--){
a[i] = a[i].toLowerCase(); //Lowercase everything
word[i] = a[i].charAt(0).toUpperCase() + a[i].substr(1,a[i].length-1); /*Uppercase just the first char on every word and put the rest of the word after it.
a[i].length-1 is optional according to MDN and will extract characters to the end of the string too*/
}
return word.join(" "); //Join and return new string
function findLongestWord(str) {
//Split input by spaces
var a = str.split(" "); // Use /\W|_/ instead to match non alphanumeric or underscore chars
//New array for lengths
var b = []; // c=""; for later returning which one (not needed for this exercise)
for (i=a.length-1; i>=0 ; i--){
//Requirements: lowercase, non-alphanumeric chars + no underscores
function palindrome(str) {
str = str.toLowerCase();
str = str.replace(/\W/g, ""); //Remove all non-alphanumeric chars
str = str.replace(/_/g, ""); //Remove all underscore chars
// Using a for loop and reduce(); not the simplest solution but succesful first attempt.
function factorialize(num) {
if (num == 0){
return 1;
}
var arr = [];
for (i=num; i>0; i--){
arr.push(i);
}
@AdrianSkar
AdrianSkar / factorialize_while.js
Last active February 19, 2018 19:44
freeCodeCamp exercise: JS factorialize a number
// Using a while loop
function factorialize(num) {
if (num == 0){
return 1;
}
var result = 1;
while (num>0){
result *= num;
@AdrianSkar
AdrianSkar / CSS-Tools.md
Created January 19, 2016 20:41 — forked from nucliweb/CSS-Tools.md
CSS Tools