Question
function maxBlock(sequence) { // TODO: Complete this function return // an integer } console.log('Testing maxBlock()') console.assert(maxBlock('abc') === 1); // You must add at least four
function maxBlock(sequence) { // TODO: Complete this function return // an integer }
console.log('Testing maxBlock()') console.assert(maxBlock('abc') === 1); // You must add at least four more console.assert()s to test this function!
// ----------------------------------------------------------------------------------- // Function isArraySorted() // // Given an array of numbers or strings, return true if all elements are in ascending // order. Note: 3 < 5, -1.5 <= 1.5, 'A' < 'a' (case sensitive). // // isArraySorted( [] ) returns true // isArraySorted( ['one'] ) returns true // isArraySorted( ['able', 'Able'] ) returns false // isArraySorted( [1, 2, 2, 99] ) returns true // isArraySorted( [1, 2, 2, -99] ) returns false // // Precondition: The argument to list has all the same type of elements, which are // either all strings or all numbers. Mix of types is not allowed! // function isArraySorted(list) { // TODO: Complete this function return // a Boolean value }
console.log('Testing isArraySorted()') console.assert(! isArraySorted(['bad','Bad'])); // 'b' > 'B' // You must add at least four more console.assert()s to test this function!
// ----------------------------------------------------------------------------------- // Function numberOfPairs // // Return the number of times a pair occurs in an array of strings or an array of numbers. // A pair is any two String values that are equal (case sensitive) in consecutive array // elements. The array may be empty or have only one element. In both of these cases, // return 0. // // numberOfPairs( [] ) returns 0 // numberOfPairs( ['a', 'b', 'c'] ) returns 0 // numberOfPairs( ['abc', 'abc', 'abc'] ) returns 2 // numberOfPairs( [1, 1, 1] ) returns 2 // numberOfPairs( [1, 1.01, 1.002] ) returns 0 // // Precondition: The argument to list has all the same type of elements. Either all // elements are numbers or all elements are strings. // function numberOfPairs(list) { // TODO: Complete this function return // an integer }
console.log('Testing numberOfPairs()') console.assert(numberOfPairs([1, 2, 2, 1]) === 1); // You must add at least four more console.assert()s to test this function!
// ----------------------------------------------------------------------------- // Function howMany // // This function returns the number of elements in the array argument list that equals // valueToFind. The array argument may be empty. // // howMany([1, 2, 3], 99 ) returns 0 // howMany(["A", "a", "A", "a" ], "A" ) returns 2, case sensitive // howMany(["And", "there", "goes", "another"], "another" ) returns 1 // howMany([39, 39, 39], 39 ) returns 3 // // Precondition: The argument to list has all the same type of elements. // Either all the elements and valueToFind are numbers or // Either all the elements and valueToFind are strings. // function howMany(list, valueToFind) { // TODO: Complete this function return // an integer }
// Add many console.assert()s to test your function! console.log('Testing howMany()') console.assert(howMany(['aa', 'bb', 'cc'], 'bb') === 1); // You must add at least four more console.assert()s to test this function!
// ----------------------------------------------------------------------------------- // Function shiftNTimes // // Modify the argument arr near the function calls so that argument is "left shifted" // n times. You must modify the array argument reference by arr by changing the parameter // list inside function shiftNTimes. A change to the parameter list inside the method // shiftNTimes changes the arguments reference by arr because both list and array // reference the same array object. // // arr = [1, 2, 3, 4, 5]; // shiftNTimes( arr, 1 ) modifies the argument arr to [2, 3, 4, 5, 1]
// arr = [1, 2, 3, 4, 5]; // shiftNTimes( arr, 2 ) modifies the argument arr to [3, 4, 5, 1, 2]
// arr = ['aa', 'bb', 'cc', 'dd', 'ee']; // shiftNTimes( arr, 3 ) modifies the argument arr to ['dd', 'ee', 'aa'', 'bb', 'cc']
// arr = ['aa', 22, true, 'bb', false, 33] // shiftNTimes( arr, 1) modifies the argument arr to [22, true, 'bb', false, 33, 'aa'] // // Precondition: The argument to list is a JS array. // function shiftNTimes(list, numShifts) { // TODO: Complete this function // // There is no return here! // You must modify the parameter list to modify the array object argument. }
console.log('Testing shiftNTimes()') /** Feel free to uncomment this test case and use it arr = [ 9, 8, 7, 6, 5 ]; shiftNTimes(arr, 2); console.assert(7 === arr[0]); console.assert(6 === arr[1]); console.assert(5 === arr[2]); console.assert(9 === arr[3]); console.assert(8 === arr[4]); */ // You must add four more test cases with arrays of different lengths. types and shifts. // This means there could be many, many console.asserts. The test case above has five.
// ----------------------------------------------------------------------------------- // Function sumGreaterThan // // Given a filled array of double array elements, return true if the sum of all // array elements is greater than sum. Return false if the array is empty. Sum // may be negative. // // sumGreaterThan( [ 1.1, 2.2, 3.3], 4.0) returns true // sumGreaterThan( [ 1.1, 2.2, 3.3], 6.6) returns false // sumGreaterThan( [ -1, 2, 3], 3.9) returns true // sumGreaterThan( [], -1.0) returns false // // Precondition: The array argument to list is always an array of numbers // function sumGreaterThan(list, sum) { // TODO: Complete this function return // a Boolean value }
console.log('Testing sumGreaterThan()') console.assert(! sumGreaterThan([1, 2, 3], 6) ); console.assert(sumGreaterThan([1, 2 ,3], 5.999) ); // You must add at least four more console.assert()s to test this function!
//----------------------------------------------------------------------- //Function countClumps() // // Say that a "clump" in an array is a series of 2 or more adjacent elements // of the same value. Return the number of clumps in the given array. // // countClumps( [ 1, 2, 3, 4 ] ) returns 0 // countClumps( [ 1, 2, 2, 2, 2, 3, 4, 4, 4, 4 ] ) returns 2 (clumps of 2 and 4) // countClumps( [ 1, 1, 2, 1, 1 ] ) returns 2 (two clumps of 1) // countClumps( [ 1, 1, 1, 1, 1 ] ) returns 1 (only one clump of 1s) // countClumps( [ 1, 2, 3] ) returns 0 // countClumps( [ 2 ] returns 0 // countClumps( [ ] returns 0 // countClumps([1, 2, 2, 3, 4, 4 ] ) returns 2 (clumps of 2 and 4) // countClumps(['a', 'b', 'c', 'c'] ) returns 1 (one clump of 'c') // countClumps(['one', 'two', 'three', 'one', 'two, 'three'] ) returns 0 // countClumps(['one', 'one', 'TWO', 'one', 'one', 'three'] ) returns 2 (2 clumps of 'one's) // // Precondition: Every array argument to list must have the same type of elements. // The only type of elements allowed are number and string. Use ===. // function countClumps(list) { // TODO: Complete this function return // an integer }
console.log('Testing countClumps()') console.assert(countClumps([1, 2, 3]) === 0); console.assert(countClumps([1, 2, 2, 2, 2, 3]) === 1); // You must add at least four more console.assert()s to test this function!
// ----------------------------------------------------------------------------------- // Function evenOdd(array) // // Modify array that contains the exact same numbers as the given array, // but rearranged so that all the even numbers come before all the odd numbers. // Other than that, the numbers can be in any order. // // arr = [1, 0, 1, 0, 0, 1, 1]; // evenOdd(arr) changes the argument arr to [0, 0, 0, 1, 1, 1, 1] // arr = [3, 3, 2]; // evenOdd(arr) changes the argument arr to [2, 3, 3] // arr = [3, 5, 4, 2]; // evenOdd(arr) changes the argument arr to [2, 4, 3, 5] or [4, 2, 3, 5] // or [2, 4, 5, 3] or [4, 2, 5, 3] // // Precondition: All array elements are integers, whole nmbers with no fractional part function evenOdd(array) { // TODO: Complete this function // // There is no return here! // // You must modify the parameter &array to modify the array object argument }
console.log('Testing evenOdd()'); /** Feel free to uncomment this test case and add more test cases arr = [1, 2, 3, -4, 5] evenOdd(arr); console.assert(arr[0] % 2 == 0); // Either 2 or -4 console.assert(arr[1] % 2 == 0); // Either 2 or -4 console.assert(arr[2] % 2 != 0); // Either 1, 3, or 5 console.assert(arr[3] % 2 != 0); // Either 1, 3, or 5 console.assert(arr[4] % 2 != 0); // Either 1, 3, or 5 */
Javascript! I will give you a thumb up thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started