Question

Javascript please show me how to do these two exercises and comment so I can understand...

Javascript please show me how to do these two exercises and comment so I can understand what's happening. Thank you.

// Execise #1

/*

Modify the function so that it returns the length of an array recursively, without using the .length property. Use recursion!

Hint: when you index outside of an array, it returns undefined

*/

function getLength(array, i = 0) {

}

// To check if you've completed the challenge, uncomment these console.logs!

// console.log(getLength([1])); // -> 1

// console.log(getLength([1, 2])); // -> 2

// console.log(getLength([1, 2, 3, 4, 5])); // -> 5


// Exercise #2

/*

Modify the function so that it returns true if a number is even (and false if it's not) assume input will be a positive integer Use recursion!

*/

function isEven(n) {

}

// To check if you've completed the challenge, uncomment these console.logs!

// console.log(isEven(0)); // -> true

// console.log(isEven(5)); // -> false

// console.log(isEven(10)); // -> true


Homework Answers

Answer #1

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

function getLength(array) {
    return 0 in array ? 1 + getLength(array.slice(1)) : 0;
}

function isEven(n) {
    if (n === 0) return true;
    if (n === 1) return false;

    return isEven(n - 2);
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Can you show steps as well? At least for one so i can practice and check...
Can you show steps as well? At least for one so i can practice and check to see if i get the same answers Find the area of the region under the graph of the function f on the interval [0, 3]. f(x) = 3ex --- [4, 9]. f(x) = 6√ x    ----- [−2, 1]. f(x) = −x2 + 7 ----- [0, 8]. f(x) = 8x − x2 ---- [−1, 5]. f(x) = 4x + 9
*In Java Please RECURSION Objectives • Learn the basics of recursion – Part II (last week...
*In Java Please RECURSION Objectives • Learn the basics of recursion – Part II (last week was Part I) Submission Guidelines: You will turn in 2 program files (one for each lab problem) Tasks This lab has two parts: 1. Write a recursive method repeatNTimes(String s, int n) that accepts a String and an integer as two parameters and returns a string that is concatenated together n times. (For example, repeatNTimes ("hello", 3) returns "hellohellohello") Write a driver program that...
*Please show your work. I do not understand how to do it* The two-way table below...
*Please show your work. I do not understand how to do it* The two-way table below summarizes how students performed in several sections of MAT 152 on the Unit 2 Test in previous semesters. The row labels are letter grades. The column labels describe whether or not a student completed all chapter quizzes for the unit (first column), or missed at least one quiz for the unit (second column). Completed all quizzes Missed at least one quiz Total A 19...
(Please show calculations and formulas that are used so I can better understand and work along....
(Please show calculations and formulas that are used so I can better understand and work along. Thanks!) GHI is considering two investment proposals. Estimated cash flows are below. Each will require an initial cash outlay, followed by several years of positive cash flows. Each project will terminate and all assets will be liquidated in year 6. GHI’s WACC is 9%. Year Project 1 Project 2 Initial outlay $1,000,000 $500,000 1 $160,000 $120,000 2 $200,000 $120,000 3 $300,000 $120,000 4 $400,000...
6.12 LAB: Grade distribution In this lab, you will write a JavaScript program that generates a...
6.12 LAB: Grade distribution In this lab, you will write a JavaScript program that generates a bar graph of letter grades from a distributions of scores. Implement the parseScores function (1 point) Implement the parseScores function to take a space-separated string of scores as an argument and return an array of score strings. Each score is a number in the range [0, 100]. Ex: "45 78 98 83 86 99 90 59" → ["45","78","98","83","86","99","59"] Hint: JavaScript's string split() function can...
[Java] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
Please show work, or steps so i can see how to do the remaining questions for...
Please show work, or steps so i can see how to do the remaining questions for the other years! Thanks 1.What is the Free Cash Flow of Diamond Construction for 2015? 2.What is the WACC for Diamond Construction? 3.Quick ratio in 2016? 4.Current ratio in 2016? Inventory turnover in 2017? Total Asset turnover in 2017? DSO in 2016? Income Statements for Diamond Construction Company 2015 2016 2017 Sales           9,445,842     10,390,426     11,637,277 COGS           7,367,757       8,104,532      ...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int...
The following algorithm finds the initial substring of y that can be reversed and found in...
The following algorithm finds the initial substring of y that can be reversed and found in y. For example, longestInitialReverseSubstringLength(“aabaa”) = 5, because “aabaa” is the same string forwards and backwards, so the longest initial substring that can be reversed and found in the string is “aabaa”. Also, longestInitialReverseSubstringLength(“bbbbababbabbbbb”) is 6, because “babbbb” can be found in the string (see color-highlighted portions of the string), but no longer initial string exists reversed in any part of the string. longestInitialReverseSubstringLength(String y)...
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm...
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm that is executed most frequently. Express the number of times it is executed as a function of N. Convert this expression into the Big-O notation. A. For each of the three fragments of code, what is its worst-case time complexity, in the form "O(…)". (Use the given solution to the first problem as a model)                 //----------------- This is a sample problem – solved ------...