Instantly share code, notes, and snippets.

# Jason Gresalfijgresalfi

• Sort options
Created Sep 14, 2016
Truncate a strin...
View truncateStr.js
 function truncateString(str, num) { if (num <= 3) { str = str.slice(0, num) + "..."; } else if (str.length > num) { str = str.slice(0, (num - 3)) + "..."; } return str; } truncateString("Jason", 1);
Created Sep 9, 2016
Confirm the Ending...match arg2 string with end of arg1 string...or don't...
View endConfirm.js
 function confirmEnding(str, target) { var fragCount = target.length, chunk = str.substring(str.length - fragCount); if (chunk === target) { return true; } else { return false; } } confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification");
Created Sep 7, 2016
Basic algorithm to count cards in Blackjack.
View cardCounting.js
 var count = 0; function cc(card) { switch (card) { case 2: case 3: case 4: case 5: case 6: count++;
Created Sep 7, 2016
Function to iterate through nested arrays and find largest values in each.
View largestOfFour.js
 function largestOfFour(arr) { for (var i = 0; i < arr.length; i++) { for (var j = 0; j < arr[i].length; j++) { arr[i] = Math.max(...arr[i]); } } return arr; } largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Created Sep 6, 2016
FCC - Title Case A Sentence
View titleCase.js
 var endArr = [], firstCap = [], finalStr = []; function theChopper(arr) { for (var i = 0; i < arr.length; i++) { firstCap.push(arr[i].charAt(0).toUpperCase()); endArr.push(arr[i].slice(1)); } }
Last active Sep 5, 2016
Find longest word in a string.
View longWord.js
 function findLongestWord(str) { var strArray = str.split(" "), arrCount = []; for (var i = 0; i < strArray.length; i++) { arrCount.push(strArray[i].length); } return Math.max(...arrCount); } findLongestWord("The quick brown fox jumped over the lazy dog");
Created Sep 4, 2016
 "use strict"; const SALESTAX = .0975, PHONE_PRICE = 200.00, ACCESS_PRICE = 40.00; var ba = prompt("How much money you got?"), ac = prompt("When to stop buying accessories?"), bankAccount = parseInt(ba), accessoryLimit = parseInt(ac),
Created Sep 4, 2016
Reversing strings
View reverseStr.js
 function reverseString(str) { var strArray = str.split(""); strArray.reverse(""); return strArray.join(""); } reverseString("hello");
Created Sep 4, 2016
Modifying objects/checking properties - record collection example
View recordCol.js
 var collection = { "2548": { "album": "Slippery When Wet", "artist": "Bon Jovi", "tracks": [ "Let It Rock", "You Give Love a Bad Name" ] }, "2468": {
Created Sep 4, 2016
Factorial! factory.
View factorializer.js
 function factorialize(num) { var facArray = []; if (num === 0) { return 1; } else { for (var i = 1; i <= num; i++) { facArray.push(i);
You can’t perform that action at this time.