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
{ | |
"quotes": [ | |
{ | |
"quote":"Life isn’t about getting and having, it’s about giving and being.","author":"Kevin Kruse"}, | |
{ | |
"quote":"Whatever the mind of man can conceive and believe, it can achieve.","author":"Napoleon Hill"}, | |
{ | |
"quote":"Strive not to be a success, but rather to be of value.","author":"Albert Einstein"}, | |
{ |
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 telephoneCheck(str) { | |
// regex that matches a phone number with no spaces, | |
// with spaces, with dashes, and with or without country code | |
let regex = /^[1]*[\s|-]*\d{3}[\s|-]*\d{3}[\s|-]*\d{4}$/; | |
// regex that matches parentheses | |
// with no spaces, with spaces, with dashes, | |
// and with or without country code | |
let regexParentheses = /^[1]*[\s]*[(]\d{3}[)][\s]*\d{3}[\s|-]*\d{4}$/; |
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 rot13(str) { | |
let codes = []; | |
for (let i = 0; i < str.length; i++) { | |
codes.push(str.charCodeAt(i)); | |
} | |
console.log(codes); | |
let newCodes = codes.map(code => { |
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 convertToRoman(num) { | |
// first split the number into decimal places | |
let str = num.toString(10); | |
let array = str.split(""); | |
// unshift string elements to an array | |
// index[3] is always thousands | |
// index[2] is always hundreds | |
// index[1] is always tens | |
// index[0] is always ones |
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 palindrome(str) { | |
// turn everything into the same case | |
let lowerStr = str.toLowerCase(); | |
// split the array into characters | |
let arr = lowerStr.split(""); | |
// remove all non-alphanumeric characters | |
let letters = arr.filter(character => { | |
let regex = /[^\W|_]/; | |
return regex.test(character); |
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 orbitalPeriod(arr) { | |
let newArr = []; | |
const GM = 398600.4418; | |
const earthRadius = 6367.4447; | |
let getOrbitalPeriod = function(avgAlt) { | |
let a = earthRadius + avgAlt; | |
let T = 2 * Math.PI * Math.sqrt(Math.pow(a,3)/(GM)); | |
return Math.round(T); | |
} |
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 Person = function(firstAndLast) { | |
let fullName = firstAndLast; | |
this.getFullName = function() { | |
return fullName; | |
}; | |
this.getFirstName = function() { | |
return fullName.split(" ")[0]; | |
return | |
} |
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 binaryAgent(str) { | |
// first split the binary string on spaces | |
let array = str.split(" "); | |
// initialize empty array to push to | |
let charcodes = []; | |
// use forEach to iterate over the array of binary codes | |
array.forEach(binstring => { | |
// parseInt the binary to get a charCode | |
let parsed = parseInt(binstring, 2); |
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 steamrollArray(arr) { | |
let stack = arr.slice(); | |
let newArr = []; | |
while (stack.length > 0) { | |
// take the last member of the parent array | |
let next = stack.pop(); | |
if (Array.isArray(next)) { | |
// if it's an array, | |
// spread it and push it back onto the stack |
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 dropElements(arr, func) { | |
// copy array to new instance with slice | |
let newArr = arr.slice(); | |
// iterate over array and try the function | |
// if function is true, break and return what's left | |
// else remove the matching newArr index | |
// which will be 0 if some have already been removed | |
for (let i = 0; i < arr.length; i++) { | |
if (func(arr[i])) { |
NewerOlder