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]); }
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...
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...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number from 1 to 10 thousand and keeps updating a count variable (count variable starts at 0 ) according to these rules: n1 = 14 n2 = 54 n3 = 123 if the number is divisible by n1, increase count by 1 if the number is divisible by n2, increase count by 2 if the number is divisible by n3, increase count by 3 if...
Please Use JavaScript and HTML 5) Number guesser (easier) Create a number guessing name, using an...
Please Use JavaScript and HTML 5) Number guesser (easier) Create a number guessing name, using an input and a button to gather a number. The number to be guessed should be a hard-coded whole number between 1 and 20. Tell the user if the number is too high, equal to, or too low than a number you have hard-coded in your application. Remove the text in the input when the user clicks the button.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT