This file contains hidden or 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
let myString = "Eleanor Roosevelt"; | |
let myRegex = /(Franklin ([A-Z]\. )?|Eleanor ([A-Z]\. )?)Roosevelt/; | |
let result = myRegex.test(myString); |
This file contains hidden or 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 pairwise(arr, arg) { | |
let sum = 0; | |
for(let i=0; i<arr.length-1; i++){ | |
for(let j=i+1; j<arr.length; j++){ | |
if(arr[i] + arr[j] === arg){ | |
sum += (i+j); | |
arr[i] = arg + 1; // to avoid the arr[i] being reused | |
arr[j] = arg + 1; // to avoid the arr[j] being reused | |
} | |
} |
This file contains hidden or 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 updateInventory(arr1, arr2) { | |
let updatedArr = []; | |
if(arr1 === []){ | |
updatedArr = arr2; | |
}else if(arr2 === []) { | |
updatedArr = arr1; | |
}else{ | |
let newItemArr = []; |
This file contains hidden or 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 checkCashRegister(price, cash, cid) { | |
let billArr = [["ONE HUNDRED", 100], ["TWENTY", 20], ["TEN", 10], ["FIVE", 5], | |
["ONE", 1], ["QUARTER", 0.25], ["DIME", 0.1], ["NICKEL", 0.05], | |
["PENNY", 0.01]]; | |
let changeDue = cash - price; | |
let sumCash = 0; | |
for(let i=0; i<cid.length; i++){ | |
sumCash += cid[i][1]; |
This file contains hidden or 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 checkCashRegister(price, cash, cid) { | |
let billArr = [["ONE HUNDRED", 100], ["TWENTY", 20], ["TEN", 10], ["FIVE", 5], | |
["ONE", 1], ["QUARTER", 0.25], ["DIME", 0.1], ["NICKEL", 0.05], | |
["PENNY", 0.01]]; | |
let changeDue = cash - price; | |
let sumCash = 0; | |
for(let i=0; i<cid.length; i++){ | |
sumCash += cid[i][1]; |
This file contains hidden or 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 telephoneCheck(str) { | |
// Good luck! | |
let regex = /^([1]\s?)?(\([0-9]{3}\)|[0-9]{3})(\s|-)?[0-9]{3}(\s|-)?[0-9]{4}$/g; | |
return regex.test(str); | |
} | |
telephoneCheck("555-555-5555"); | |
/* | |
telephoneCheck("1 555-555-5555")should return true. |
This file contains hidden or 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 rot13(str) { // LBH QVQ VG! | |
let newStr = ''; | |
for(let i=0; i<str.length; i++){ | |
let asciiCode = str.charCodeAt(i); | |
if(asciiCode>=78 && asciiCode <=90){ | |
asciiCode = asciiCode - 13; | |
}else if(asciiCode <78 && asciiCode >= 65){ | |
asciiCode = asciiCode + 13; | |
} | |
newStr += String.fromCharCode(asciiCode); |
This file contains hidden or 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 convertToRoman(num) { | |
let roman = ''; | |
let roman1 = ''; | |
let roman10 = ''; | |
let roman100 = ''; | |
let roman1000 = ''; | |
let numStr = '' + num; | |
if(num<10){ | |
switch(numStr[0]){ | |
case '1': roman1 = 'I'; break; |
This file contains hidden or 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 palindrome(str) { | |
// Good luck! | |
let newStr = str.replace(/\W|_/g, ''); | |
newStr = newStr.toLowerCase(); | |
let revStr = newStr.split('').reverse().join(''); | |
if(newStr === revStr){ | |
return true; | |
} | |
return false; | |
} |
This file contains hidden or 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 palindrome(str) { | |
let newStr = str.replace(/\W/g, ''); | |
newStr = newStr.replace('_', '').toLowerCase(); | |
let revStr = newStr.split('').reverse().join(''); | |
if(newStr === revStr){ | |
return true; | |
} | |
return false; | |
} |
NewerOlder