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 permAlone(str) { | |
//check if the string provided is only one character | |
if(str.length === 1){ | |
return 1; | |
} | |
//function to create the permutations | |
//for each value in the string, add the permutations of the rest | |
function getPermutations(str){ | |
var output = []; |
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 updateInventory(arr1, arr2) { | |
// All inventory must be accounted for or you're fired! | |
//check the items in arr2 against those in arr1 | |
//if the item is found update the value and set found to true. | |
//if the item is not found add it to arr1 | |
for(var i = 0; i < arr2.length; i++){ //loop over array 2 | |
var found = false; | |
for(var j = 0; j<arr1.length; j++){ //loop over array 1 | |
if(arr2[i][1] === arr1[j][1]){ |
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
/* UPDATED NOVEMBER 2021 to work with the latest FreeCodeCamp tests | |
Design a cash register drawer function checkCashRegister() that accepts purchase price as the first argument (price), | |
payment as the second argument (cash), and cash-in-drawer (cid) as the third argument. | |
cid is a 2D array listing available currency. | |
The checkCashRegister() function should always return an object with a status key and a change key. | |
Return {status: "INSUFFICIENT_FUNDS", change: []} if cash-in-drawer is less than the change due, or if you cannot return | |
the exact change. | |
Return {status: "CLOSED", change: [...]} with cash-in-drawer as the value for the key change if it is equal to the change due. | |
Otherwise, return {status: "OPEN", change: [...]}, with the change due in coins and bills, sorted in highest to lowest order, | |
as the value of the change key. |
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 sym(args) { | |
//Put the arguments into an array | |
var arrArgs = Array.prototype.slice.call(arguments); | |
//Function to compare two arrays by reducing each one in | |
//comparison with the other. Check if the item in first array | |
//is also in the second array, if it isn't push it to the accumulator. | |
//then repeat the other way around. | |
function compareArrays(arr1, arr2){ |
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
// Setup | |
var collection = { | |
"2548": { | |
"album": "Slippery When Wet", | |
"artist": "Bon Jovi", | |
"tracks": [ | |
"Let It Rock", | |
"You Give Love a Bad Name" | |
] |
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) { | |
// Good luck! | |
var regex = /(^1(?=(\s\d{3}\s?-?\d{3}\s?-?\d{4}$)|(\s?\(\d{3}\)\s?-?\d{3}\s?-?\d{4}$)))|(^\((?=\d{3}\)\s?-?\d{3}\s?-?\d{4}$))|(^\d{3}(?=\s?-?\d{3}\s?\-?\d{4}$))/; | |
return regex.test(str); | |
} | |
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 addTogether() { | |
//create a function that test whether arguments are numbers | |
//if not a number return undefined, if it is return the number | |
function checkArgs(val){ | |
if(typeof val !== 'number'){ | |
return undefined; | |
} | |
return val; | |
} |
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 truthCheck(collection, pre) { | |
// Is everyone being true? | |
//set a variable to count the truthies | |
var truthy = 0; | |
//loop over the array and test for true | |
//if it's true add one to truth | |
for(var i = 0; i<collection.length; i++){ | |
if(collection[i][pre]){ | |
truthy ++; | |
} |
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) { | |
var arr = str.split(' '); | |
//var words = []; | |
for(var i =0; i<arr.length; i++){ | |
arr[i] = parseInt(arr[i], 2); | |
arr[i] = String.fromCharCode(arr[i]); | |
//can also write the above as: | |
//words.push(String.fromCharCode(parseInt(arr[i], 2))); | |
//parses first then converts to letter then pushes to array. | |
} |
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) { | |
// I'm a steamroller, baby | |
var result = []; //store the resulting flat array | |
//function to recursively flatten arrays inside of arrays. | |
function flatten(arr){ | |
//for every item in the array check if it is an array itself | |
for(var i = 0; i < arr.length; i++){ | |
if(Array.isArray(arr[i]) ){ | |
//if it is an array call the flatten function and concatinate the results |