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
// 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. |
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
// Return true if the passed string looks like a valid US | |
// phone number. | |
// The user may fill out the form field any way they choose | |
// as long as it has the format of a valid US number. The | |
// following are examples of valid formats for US numbers | |
// (refer to the tests below for other variants): | |
// 555-555-5555 (555)555-5555 (555) 555-5555 555 555 5555 | |
// 5555555555 1 555 555 5555 |
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
// One of the simplest and most widely known ciphers is a Caesar cipher, | |
// also known as a shift cipher. In a shift cipher the meanings of the | |
// letters are shifted by some set amount. | |
// A common modern use is the ROT13 cipher, where the values of the | |
// letters are shifted by 13 places. Thus 'A' ↔ 'N', 'B' ↔ 'O' and so on. | |
// Write a function which takes a ROT13 encoded string as input and | |
// returns a decoded string. |
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
// Convert the given number into a roman numeral. | |
// All roman numerals answers should be provided in upper-case. | |
function convertToRoman(num) { | |
let thousands = ["", "M", "MM", "MMM"]; | |
let hundreds = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"]; | |
let dozens = ["", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"]; | |
let singles = ["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"]; | |
return thousands[Math.floor(num / 1000)]+ |
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
// Return true if the given string is a palindrome. Otherwise, | |
// return false. | |
// A palindrome is a word or sentence that's spelled the same | |
// way both forward and backward, ignoring punctuation, case, | |
// and spacing. | |
// Note | |
// You'll need to remove all non-alphanumeric characters (punctuation, | |
// spaces and symbols) and turn everything into the same case | |
// (lower or upper case) in order to check for palindromes. |
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
// Return a new array that transforms the elements' average | |
// altitude into their orbital periods (in seconds). | |
// The array will contain objects in the format {name: 'name', | |
// avgAlt: avgAlt}. | |
// You can read about orbital periods on Wikipedia. | |
// The values should be rounded to the nearest whole number. | |
// The body being orbited is Earth. | |
// The radius of the earth is 6367.4447 kilometers, and the GM | |
// value of earth is 398600.4418 km3s-2. |
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
// Fill in the object constructor with the following methods below: | |
// getFirstName() getLastName() getFullName() setFirstName(first) | |
// setLastName(last) setFullName(firstAndLast) | |
// Run the tests to see the expected output for each method. | |
// The methods that take an argument must accept only one argument | |
// and it has to be a string. | |
// These methods must be the only available means of interacting with |
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
// Create a function that sums two arguments together. If only | |
// one argument is provided, then return a function that expects | |
// one argument and returns the sum. | |
// For example, addTogether(2, 3) should return 5, and addTogether(2) | |
// should return a function. | |
// Calling this returned function with a single argument will then | |
// return the sum: | |
// var sumTwoAnd = addTogether(2); | |
// sumTwoAnd(3) returns 5. | |
// If either argument isn't a valid number, return undefined. |
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
// Check if the predicate (second argument) is truthy on all | |
// elements of a collection (first argument). | |
// In other words, you are given an array collection of objects. | |
// The predicate pre will be an object property and you need to | |
// return true if its value is truthy. Otherwise, return false. | |
// In JavaScript, truthy values are values that translate to true | |
// when evaluated in a Boolean context. | |
// Remember, you can access object properties through either dot |
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
// Intermediate Algorithm Scripting: Binary Agents | |
// Return an English translated sentence of the passed binary string. | |
// The binary string will be space separated. | |
function binaryAgent(str) { | |
return str.split(" ").map(letter => String.fromCharCode(parseInt(letter,2).toString())).join(""); | |
} | |
binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111"); // "Aren't bonfires fun!?" |
NewerOlder