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

This is for Python programming, and I am trying to use 2 for loops to ask...
This is for Python programming, and I am trying to use 2 for loops to ask a slaesperson how many of 5 different items they sold, then the program is to calculate the total dollar amount sold. Formatting and all that aside, I am having an issue with the loops not stepping through the 2 lists at the same time. The first loop is taking all 5 entered quantities times the price of the first item, and then all 5...
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; }
Solve this question in C++ language. DO NOT use loops. Use recursive function. Keep the program...
Solve this question in C++ language. DO NOT use loops. Use recursive function. Keep the program simple. Q (5) Suppose you have been given the task to design a text editor which will take any multiline text from user and then display the statistics like total number of characters i.e., characters_count (excluding the white space and punctuations), words_count, and redundant_words_count. Create a structure named Text_Editor having four type members namely inserted_text (of type string), characters_count (of type unsigned int), words_count...
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...
Exercise 1 (a) Use javascript modify the code below, so that in addition to outputting the...
Exercise 1 (a) Use javascript modify the code below, so that in addition to outputting the selection to the web page, the selection is also placed in the browser’s local storage. Use ‘select’ as the local-storage key. The value will be the name of the category that was selected or the empty string is no selection was made. (d) Add a button called ‘retrieve’. When it is clicked the local storage is read and the prior selection is shown on...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT