Question

In: Computer Science

Solve for number 2, Use Functional Programming ONLY, so No For loops Use JavaScript: Start with...

Solve for number 2, Use Functional Programming ONLY, so No For loops

Use JavaScript:

  1. Start with an array called inputtable. The array should have numbers between 1 and 10.

NOTE: Do NOT use a form of a ‘for’ loop anywhere, including iterators. This is meant to be a functional exercise.

  1. Get the odd multiples of 5 between 1 and 100. 5, 15, …

Solutions

Expert Solution

Here is the answer for your question in JavaScript Programming Language.

Kindly upvote if you find the answer helpful.

NOTE : As mentioned I haven't used any 'for' loops but used 'functional programming' concept 'recursion' to achieve the output.

##################################################################

CODE :

//Required variables and array objects

var count = 1;

var inputtable = new Array();

var resultArray = new Array();

//Call the functions

createArray();

oddMultiples(inputtable);

//Print result

resultArray.reverse();

console.log(resultArray);

//Recursive function that gets odd multiples of 5 between 1 and 100

function oddMultiples(inputtable){

if(count === 1)

return;

else{

if(inputtable[count] % 5 === 0){

if(inputtable[count] % 2 === 1)

resultArray.push(inputtable[count]);

}

count--;

return oddMultiples(inputtable);

}

}

//Recrisive function that creates and array of numbers between 1 and 100

function createArray(){

if(count === 100)

return;

else{

inputtable.push(count);

count++;

return createArray();

}

}


###################################################

SCREENSHOTS :

Please see the screenshots of the code below for the indentations of the code.

###################################################

OUTPUT :

Any doubts regarding this can be explained with pleasure :)


Related Solutions

Be sure to use only C for the Programming Language in this problem. Before we start...
Be sure to use only C for the Programming Language in this problem. Before we start this, it is imperative that you understand the words “define”, “declare” and “initialize” in context of programming. It's going to help you a lot when following the guidelines below. Let's begin! Define two different structures at the top of your program. be sure to define each structure with exactly three members (each member has to be a different datatype). You may set them up...
Split the Number IN JAVASCRIPT Programming challenge description: You are given a number N and a...
Split the Number IN JAVASCRIPT Programming challenge description: You are given a number N and a pattern. The pattern consists of lowercase latin letters and one operation "+" or "-". The challenge is to split the number and evaluate it according to this pattern e.g. 1232 ab+cd -> a:1, b:2, c:3, d:2 -> 12+32 -> 44 Input: Your program should read lines from standard input. Each line contains the number and the pattern separated by a single whitespace. The number...
C programming Rewrite the following function using no loops, and only tail call recursion double question5...
C programming Rewrite the following function using no loops, and only tail call recursion double question5 (int in) { int i; int result; for (result = rand(), i = 0; i < in; i += 3) { result /= i; result += rand(); } return result; }
Linear programming. Solve the following two (2) Linear programming problems (#1 and #2) and then answer...
Linear programming. Solve the following two (2) Linear programming problems (#1 and #2) and then answer question 3: 1.. Solve the following LP problem graphically: Maximize profit =            X + 10Y Subject to:                        4X + 3Y < /= 36                                            2X +4Y < / = 40                                            Y > / = 3                                            X, Y > / = 0 2. Considering the following LP problem and answer the questions, Part a and Part b: Maximize profit =            30X1...
THE STRING MATCH PROBLEM C++ only. Must use loops. Please do not use sequence of if...
THE STRING MATCH PROBLEM C++ only. Must use loops. Please do not use sequence of if statements. . Given 2 strings, a and b, set result to the number of the positions where they contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3, since the "xx", "aa", and "az" substrings appear in the same place in both strings. • for input of "xxcaazz", "xxbaaz" → 3 • for input of "abc", "abc" → 2 • for input...
Modify the following code to use ONLY pointer arithmetic (no array expressions) and no for loops...
Modify the following code to use ONLY pointer arithmetic (no array expressions) and no for loops to do the same thing this code does. Be sure that you understand how the code works and how the pointer arithmetic relates to the array expression form. Provide liberal comments to explain what your pointer arithmetic is computing. #include <stdlib.h> #include <stdio.h> int main(int argc, char **argv) { int arg_count = 0; for (arg_count = 0; arg_count < argc; arg_count++) printf("%s\n", argv[arg_count]); }
In the given instruction, I am to use while loops only. The goal is to prompt...
In the given instruction, I am to use while loops only. The goal is to prompt the user to select an acceptable input. If the wrong input is given, the program forces the user to select an appropriate input. The program also keeps running until the user chooses to exist by selecting a very specific input which in my case is the upper or lower case "E". The problem is even after selecting upper or lower case "E", my program...
Instructions: 1. Please use only C as the language of programming. 2. Please submit the following:...
Instructions: 1. Please use only C as the language of programming. 2. Please submit the following: (1) the client and the server source files each (2) a brief Readme le that shows the usage of the program. 3. Please appropriately comment your program and name all the identifiers suitable, to enable enhanced readability of the code. Problem: Write an ftp client and an ftp server such that the client sends a request to ftp server for downloading a file. The...
Formulate and solve a linear programming model to deter­ mine the number of Family Thrillseekers and...
Formulate and solve a linear programming model to deter­ mine the number of Family Thrillseekers and the number of Classy Cruisers that should be assembled Before she makes her final production decisions, Rachel plans to explore the following questions independently, except where otherwise indicated. The marketing department knows that it can pursue a targeted $500,000 advertising campaign that will raise the demand for the Classy Cruiser next month by 20 percent. Should the campaign be undertaken? Rachel knows that she...
In MATLAB FOR loops: Repeat a block command a certain number of times Use a loop...
In MATLAB FOR loops: Repeat a block command a certain number of times Use a loop index Can use a non-unit stride Are required for any kind of animations An accumulator: MUST start at zero Can be used to keep track of a quantity each time through the loop Can be used to calculate how a sum changes with each loop Should be coded, for loops are more efficient For loops: Perform a set task a set number of times...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT