Write the function array_dup

Assignment Help Programming Languages
Reference no: EM131182168

Problem 1:

Write the function array_dup(n, obj) that returns an array containing n copies of obj.

>> array_dup(5, "hi")

=> ["hi", "hi", "hi", "hi", "hi"]

Ensure the array that gets returned contains independent copies of obj:

>> c = array_dup(5, [1,2])

=> [[1, 2], [1, 2], [1, 2], [1, 2], [1, 2]]

>> c[0].delete(1)

=> 1

>> c

=> [[2], [1, 2], [1, 2], [1, 2], [1, 2]]

Problem 2:

Write a function count_occurrences(a, obj) that counts the number of items in array a that are equal to obj.

>> a

=> [1, 2, 1, 3, 1, 4, 2, 5]

>> count_occurrences(a, 1)

=> 3

Problem 3:

Write a function insert(x, a) that takes an integer x and an array aof integers in nondecreasing order and returns a new sorted array that includes x and the integers of a. Your function should not modify a.

>> a = [2, 4, 5, 9, 12]

=> [2, 4, 5, 9, 12]

>> insert(5, a)

=> [2, 4, 5, 5, 9, 12]

>> insert(10, a)

=> [2, 4, 5, 9, 10, 12] >> insert(20, a)

=> [2, 4, 5, 9, 12, 20]

>> a

=> [2, 4, 5, 9, 12]

Reference no: EM131182168

Questions Cloud

Determine the conditions on the coefficients : Using the rref command on your calculator, determine the conditions on the coefficients in order for there to be a unique solution.
Improve the survey if it were to be repeated : a. Using complete sentences, list three things wrong with the way the survey was conducted. b. Using complete sentences, list three ways that you would improve the survey if it were to be repeated.
Discuss the differences between legitimate and reward : Discuss the differences between legitimate, reward, coercive, and referent power. Give an example of each or the appropriate uses of these expert powers
Markov analysis and forecasting : 1. According to Markov Analysis and Forecasting describe the internal labor market of the company in terms of job stability, promotion paths and rates, transfer paths and rates, demotion paths and rates, and turnover rates?
Write the function array_dup : Write the function array_dup(n, obj) that returns an array containing n copies of obj - Write a function count_occurrences(a, obj) that counts the number of items in array a that are equal to obj.
Did any of the other goals figure in this decision : Which of the goals listed in Table 1.1 was most important to you (and perhaps to your family or community, if they were involved) in making this decision? Did any of the other goals figure in this decision? If you were to write up a list of your o..
Identify and describe a business crisis : Identify and describe a business crisis situation and the main leaders involved. It could be one that you have experienced or have read about. Be sure to include a discussion of ethical implications
Dosages resembles a normal distribution reasonably closely : In a sample of 100 syringes, the hospital's quality control officer finds the average dosage to be 0.5mL. The standard deviation of the dosage is 0.02 mL and the distribution of the dosages resembles a normal distribution reasonably closely.
How will you sell the product in that country : What is the product that you plan to sell? -  What foreign country do you plan to target?  -  How will you sell the product in that country?

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd