Question: // Function romanNumeral // // Complete the free function romanNumeral that returns the numeric // equivalent of an upper- or lower-case Roman letter, which is

// Function romanNumeral // // Complete the free function romanNumeral that returns the numeric // equivalent of an upper- or lower-case Roman letter, which is a string // length of exactly 1. // // Recommended: Change numeral to either upper or lower case: Example // letter = letter.toUpperCase(); // // Roman numerals and their decimal equivalents are: // // romanNumeral('I') (or 'i') returns 1 // romanNumeral('V') (or 'v') returns 5 // romanNumeral('X') (or 'x') returns 10 // romanNumeral('L') (or 'l') returns 50 // romanNumeral('C') (or 'c') returns 100 // romanNumeral('D') (or 'd') returns 500 // romanNumeral('M') (or 'm') returns 1000 // // If the input is not a valid Roman letter, return -1 // // Precondition: numeral.length === 1 // function romanNumeral(letter) { // TODO: Complete this function return null; // null should never be returned. Return 1,5,10,50,100... }

console.assert(romanNumeral('G') === -1) // Add many more console.asserts

// ---------------------------------------------------------------------- // Function sumOfFirstInts // // Return the sum of the first n integers. // // sumOfFirstInts(2) returns 3, which is 1 + 2 // sumOfFirstInts(3) returns 6, which is 1 + 2 + 3 // sumOfFirstInts(5) returns 15, which is 1 + 2 + 3 + 4 + 5 // // Precondition: n >= 0 (no negatives, integers only) // function sumOfFirstInts(n) { // TODO: Complete this function return null; // null should never be returned. Return an integer number }

// ------------------------------------------------------------------------- // Function factorial // // Given an integer n, return n! // factorial(0) returns 1 // factorial(1) returns 1 // factorial(2) returns 2 which is 2 * 1 // factorial(3) returns 6 which is 3 * 2 * 1 // factorial(4) returns 24 which is 4 * 3 * 2 * 1 // // Precondition: 0 <= n <= 21 and is an integer. You should // always be able to return a valid result in this range. // 22! can not be represetented as 22 * 51,090,942,171,709,440,000 (21!) // function factorial(n) { // TODO: Complete this function return null; // null should never be returned. Return an integer number. }

// --------------------------------------------------------------------- // Function beHappy // // We'll say that a lowercase 'b' in a string is 'happy' // if there is another 'b' immediately to its left or right. // Return true if all the b's in the given string are happy. // If there are no b's return true, // // beHappy('') returns true There are no b's // beHappy('aaMMnn') returns true There are no b's // beHappy('b') returns false There is no b on either side // beHappy('xxbxx') returns false // beHappy('xxbbxx') returns true Both bs have a b on one side // beHappy('xxbbbxyz') returns true // beHappy('qrbbstbuv') returns false One bis 'alone' // A 'b' at index 0 can not have another 'b' to its left // beHappy("bxxbbbxx") returns false // // A 'b' at the last index can not need have another to its right // beHappy("xxbbbxxb") returns false // // Precondition: all characters in str will be lower case // function beHappy(str) { // TODO: Complete this function return null; // null should never be returned. Return a Boolean value. }

// --------------------------------------------------------------------- // Function increment // // Add inc to every array element in the argument. // Do not return a modified array (see the test code below). // function increment(array, inc) { // TODO: Modify all array elements by inc // Do not return anything!

JavaScript please

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!