This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// props I don't want shared for each obj | |
// constructor function | |
function Vehicle(make, model, year){ | |
this.make = make; | |
this.model = model; | |
this.year = year; | |
this.isRunning = false; | |
} | |
// functions I want each obj to have |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require("express"); | |
var app = express(); | |
app.get("/", function(req, res){ | |
res.send("Hi there, welcome to my practice run!"); | |
}); | |
app.get("/speak/:animal", function(req, res){ | |
var sounds = { | |
pig: "Oink", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"/> // added slash outside of WP to recognize all below | |
// Left Navigation - Selectors | |
var header = document.getElementById('hb-header'); | |
var headerInner = document.getElementById('header-inner'); | |
var pageHeader = document.getElementById('hb-page-title'); | |
var dataSpecContainer = document.querySelector('.data-spec'); | |
var leftNavCol = document.getElementById('nav-column'); | |
var navTrees = document.querySelectorAll('.nav-tree'); | |
var navSubTrees = jQuery('.nav-tree__sub-nav a'); | |
var navContainer = jQuery('.nav-tree__container'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TARGET_PATH = path.resolve(`./documents/tempdocs/yourSetFolder`); | |
var IMAGE_TYPES = ['image/jpeg', 'image/png']; | |
var yourPhotoUpload = { | |
index: (req, res, next) => { | |
res.render('index'); | |
}, | |
upload: (req, res, next) => { | |
// UPLOAD LOCAL TEMP | |
var is, os, targetPath, targetName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//this solution performs at minimum 7x better, at maximum infinitely better. | |
function palindrome(str) { | |
//assign a front and a back pointer | |
let front = 0 | |
let back = str.length - 1 | |
//back and front pointers won't always meet in the middle, so use (back > front) | |
while (back > front) { | |
//increments front pointer if current character doesn't meet criteria | |
if ( str[front].match(/[\W_]/) ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function largestOfFour(arr) { | |
// array to hold results of 4 sub-arrays | |
var largestNum = [0,0,0,0]; | |
//nested for loops to iterate through array and sub-array | |
for (var i = 0; i < arr.length; i++) { | |
for (var j = 0; j < arr[i].length; j++) { | |
if (arr[i][j] > largestNum[i]) { | |
largestNum[i] = arr[i][j]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// written out by hand - first in pseudocode, then actual code, and then tested in browser | |
function findLongestWord(str) { | |
var arrElem = str.split(" "); // str to array with space delimiter in bw | |
var maxElem = arrElem[0]; // default longest element to first index of array | |
for (var i = 0; i < arrElem.length; i++) { | |
if (arrElem[i].length >= maxElem.length) { // compares length of each to previous maxElem | |
maxElem = arrElem[i]; // sets new maxElem if greater than | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// learned to clean up code and execute multiple functions in a single line | |
// learned to use regular expressions and the replace function | |
function palindrome(str) { | |
var re = /[^A-Za-z0-9]/g; // regular expression removes all non-alphanumeric char | |
var string = str.toLowerCase().replace(re,''); // lower case, replace char w/no char in bw | |
var revArray = string.split('').reverse().join(''); // str to array, reverse, array to str | |
return string === revArray; // returns true if equal, otherwise false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example of recursive algorithm | |
function factorialize(num) { | |
if (num < 0) { | |
return -1; // error msg | |
} | |
else if (num === 0) { | |
return 1; // base case | |
} | |
else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reverseString(str) { | |
var string = str; | |
var array = []; | |
array = string.split(''); // turns string into an array of char | |
var revArray = array.reverse(); // reverses elements of array | |
var newStr = revArray.join(''); // joins reversed elements of array into a string w/ no char in between | |
return newStr; // returns reversed string |
NewerOlder