Hey I was wondering if you can help me out with these two
questions:
1. Correct the implementation of JavaScript function below assuming
that the documentation is correct. Use a highlighter to identify
your corrections.
/** Maps items from an array using a function.
* @arg {array} array Array to map.
* @arg {function(item,index)} fun Function to call for each item.
The return value is appended to the output array, unless
undefined.
* @arg {array} [out] Optional output array.
* @ret {array} The output array. */
function map(array, fun, out) {
var n = array.length,
m = out.length,
i;
if (out === null)
out = []
for (i = 0; i <= n; ++i)
v = array[i];
v = fun(v, i);
if (v !== undefined) {
out[++m] = v;
}
}
2. Assuming the implementation in question 1 is correct and it
functions as documented, what is the return value of the
following?
var a1 = [2, 4, 5];
var a2 = ["hello"];
function incr(v, i) {
if (v % 2) return v + 1;
}
return map(a1, incr, a2);
1.
function map(array, fun, out) {
var n = array.length,
m = out.length,
if (out === null)
out = []
for (let i = 0; i <= n; ++i)
v = array[i];
v = fun(v, i);
if (v !== undefined) {
out[m++] = v;
}
return out;
}
2.
incr(2, 0) -> undefined since 2 % 2 != 1
incr(4, 0) -> undefined since 4 % 2 != 1
incr(5, 0) -> 6 since 5 % 2 = 1
Hence, 5 is appended to the array a2.
Hence, the contents of ar are:
["hello", 5]
Hey I was wondering if you can help me out with these two questions: 1. Correct...
Hey everyone, I need help making a function with this directions
with C++ Language.
Can you guys use code like printf and fscanf without iostream or
fstream because i havent study that yet.
Thanks.
Directions: Write a function declaration and definition for the char* function allocCat. This function should take in as a parameter a const Words pointer (Words is a defined struct) The function should allocate exactly enough memory for the concatenation of all of the strings in the...
Greeting! Kindly help me to solve my finals in PYTHON, I don't have a knowledge in PYTHON, new student. Please, please, I'm begging, Kindly answers all the questions. I'm hoping to grant my request. Thanks in advanced. 1.) What is the output of the following snippet? l1 = [1,2] for v in range(2): l1.insert(-1,l1[v]) print(l1) a.) [1, 2, 2, 2] b.) [1, 1, 1, 2] c.) [1, 2, 1, 2] d.) [1,...
Hey guys, I need some help solving this problem. thank
you very much in advance!
Pontfolio Optimization Task 4 Suppose the shares of two different companies give you the same return on average. Does it make sense to distribute your money and buy some shares of each company? Or would it be better to invest all the money into only a single company? Common sense says: "distribute" Why? Let's see... What at all could we gain if the return is...
Hello! I'm posting this program that is partially completed if someone can help me out, I will give you a good rating! Thanks, // You are given a partially completed program that creates a list of employees, like employees' record. // Each record has this information: employee's name, supervisors's name, department of the employee, room number. // The struct 'employeeRecord' holds information of one employee. Department is enum type. // An array of structs called 'list' is made to hold...
using C++ language!! please help me out with
this homework
In this exercise, you will have to create from scratch and utilize a class called Student1430. Student 1430 has 4 private member attributes: lastName (string) firstName (string) exams (an integer array of fixed size of 4) average (double) Student1430 also has the following member functions: 1. A default constructor, which sets firstName and lastName to empty strings, and all exams and average to 0. 2. A constructor with 3 parameters:...
I'm having trouble writing this code, can some help me? Step 1: Capturing the input The first step is to write a functionGetInput()that inputs the expression from the keyboard and returns the tokens---the operands and operators---in a queue. You must write this function. To make the input easier to process, the operands and operators will be separated by one or more spaces, and the expression will be followed by #. For example, here’s a valid input to your program: 6...
I NEED HELP WITH THIS HOMEWORK!!!! What is a characteristic of a bag data type? Elements are added and removed in any order Elements are removed in the same order they were added Distinct elements are added in any order but are removed beginning with the last one added Distinct elements are removed in the reverse order they were added Which scenario illustrates a data stack structure Standing in a line to be serviced Filing documents in alphabetical order Offering...
Please can someone help me to finish this program? It is a C
programming not a C++, when programming the program in linux I keep
getting expected expression before || token, also please check if
everything else is fine, maybe there is something else worng in my
program and may ask me later to fix it, I am concern about the sin
and cosine. The program is supposed to do all this:
1.Display a welcome message.
2.Prompt for the height...
I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME
OUT AND READ THIS. I just have to explain a lot so you understand
how the program should work.
In C programming, write a simple program to
take a text file as input and encrypt/decrypt it by reading the
text bit by bit, and swap the bits if it is specified by the first
line of the text file to do so (will explain below, and please let
me...
URGENT
I have 3 hours for Submit this Homework so you can share
yout codes with me in 150mins
Preliminary Notes: You have 4 hours to submit your solution. No late submission is accepted. Do not leave your submission to the last minute. You are not allowed to copy any code from anywhere. Your code will be checked by a software for similarity. Implement the code on your own and never share it with someone else. A test code is...