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...
Code in Python. You can only use while loops NOT for loops. Program 1: cost_living In...
Code in Python. You can only use while loops NOT for loops. Program 1: cost_living In 2020 the average cost of living/month (excluding housing) for a family of 4 in Pittsburgh was $3850 per month. Write a program to print the first year in which the cost of living/month is over $4450 given that it will rise at a rate of 2.1% per year. (Note:  this program requires no input). Program 2: discount A discount store is having a sale where...
Activity 11: JS-Loops and Functions Task 1: Use JavaScript for loop to print the first 5...
Activity 11: JS-Loops and Functions Task 1: Use JavaScript for loop to print the first 5 non-zero integers on each line. Task 2: Use JavaScript while loop to print the first 5 non-zero integers on each line. Task 3: Use JavaScript for loop to print the first 5 even integers on each line. Task 4: Write a JavaScript function to multiple two numbers and return the result. Task 5: Write a JavaScript factorial that asks users to enter a positive...
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...
Write a program in c++ using only while and for loops . Use of arrays and...
Write a program in c++ using only while and for loops . Use of arrays and functions is not allowed. Given the first value, generate the next ten terms of the sequence like 1, 2, 4, 8, 16, 22, 26, 38, 62, 74, 102, 104, … Explaination with code is required.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT