Skip to content

Instantly share code, notes, and snippets.

@denismcdonald
denismcdonald / profileLookup.js
Last active May 21, 2018 23:43
freeCodeCamp Basic Javascript challenge: Profile Lookup (solution with Object.values)
//Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
@denismcdonald
denismcdonald / profileLookup.js
Last active May 21, 2018 23:43
freeCodeCamp Basic JavaScript Challenge: Profile Lookup (simpler solution, with hasOwnProperty)
//Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
@denismcdonald
denismcdonald / checkForPalindromes.js
Last active May 23, 2018 03:31
Check to see if string contains palindrome (JavaScript)
function palindrome(str) {
var strAlt = str.toLowerCase();
strAlt = strAlt.replace(/\s/g, "");
strAlt = strAlt.replace(/\W/g, "");
strAlt = strAlt.replace(/_/g, "");
if (strAlt.split("").reverse().join("") == strAlt) {
return true;
} else {
@denismcdonald
denismcdonald / findLongestWord.js
Last active May 23, 2018 03:31
Find the longest word in a sentence and return word length (JavaScript)
function findLongestWord(str) {
var splitString = str.split(" ");
var longestString = splitString[0];
for (var i = 0; i < splitString.length; i++) {
if (splitString[i].length > longestString.length) {
longestString = splitString[i];
}
}
@denismcdonald
denismcdonald / capitaliseFirstWord.js
Last active May 23, 2018 03:31
Capitalise the first letter of each word in a string (and otherwise convert to lower case) (JavaScript)
function titleCase(str) {
var splitString = str.split(" ");
var newArray = [];
for (var i = 0; i < splitString.length; i++) {
var splitWord = splitString[i].split("");
splitWord[0] = splitWord[0].toUpperCase();
for (var j = 1; j < splitWord.length; j++) {
@denismcdonald
denismcdonald / returnLargestFromArrays.js
Created May 24, 2018 01:59
Return largest numbers from sub-arrays (JavaScript)
function returnLargest(arr) {
var newArr = [];
for (var i = 0; i < arr.length; i++) {
var subArray = arr[i];
var largest = arr[i][0];
for (var j = 0; j < arr[i].length; j++) {
if (subArray[j] > largest) {
@denismcdonald
denismcdonald / forEach-querySelectorAll.js
Created July 11, 2018 10:25
forEach method for querySelectorAll (JavaScript)
var elements = document.querySelectorAll("h1");
Object.keys(elements).forEach(function(key) {
elements[key].style.color = "orange";
});
/* ------------------------------------------------------------------------------------------------------ */
/*--- Z-INDEX STANDARDS ---*/
/* ------------------------------------------------------------------------------------------------------ */
/* 9999 - tapestry popups/error messages/etc. (must be closeable) */
/* 9998 - assorted items with high z-index (formerly 9999999999 - modal resize icon, dropdown item, etc.) */
/* 9997 - assorted items with high z-index (formerly 999999999) */
/* 9996 - formerly 99999 (ui-resizable-handle) */
/* 9995 - formerly 9999 (modal background, more_info_container, a couple of others) */