Skip to content

Instantly share code, notes, and snippets.

Jason Gresalfi jgresalfi

Block or report user

Report or block jgresalfi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jgresalfi
jgresalfi / truncateStr.js
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);
@jgresalfi
jgresalfi / endConfirm.js
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");
@jgresalfi
jgresalfi / cardCounting.js
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++;
@jgresalfi
jgresalfi / largestOfFour.js
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]]);
@jgresalfi
jgresalfi / titleCase.js
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));
}
}
@jgresalfi
jgresalfi / longWord.js
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");
@jgresalfi
jgresalfi / phoneBuyerz.js
Created Sep 4, 2016
Silly phone buying app...
View phoneBuyerz.js
"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),
View reverseStr.js
function reverseString(str) {
var strArray = str.split("");
strArray.reverse("");
return strArray.join("");
}
reverseString("hello");
@jgresalfi
jgresalfi / recordCol.js
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": {
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.