Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Magical Indices

Given an array of integers and a number

  • x. An index is valid ifitem y at an index is increased by x and
  • x+y would be greater than the sum of all other items in the array.

Write a JS program to determine the number of valid indices.

Input

  • The first line of input contains an array
  • The second line of input contains a number

Output

  • The output should be a number indicating the number of valid positions

Explanation

For example, an array A = [10, 20, 30] and a value x = 25.

We have values 10, 20, 30 at indices 0,1,2 respectively.

  • Here index 0 is invalid because
  • 10 + 25 = 35 is less than 20 + 30 = 50
  • Here index 1 is valid because
  • 20 + 25 = 45 is greater than 10 + 30 = 40
  • Here index 2 is valid because
  • 30 + 25 = 55 is greater than 10 + 20 = 30

So there are 2 valid indices.

Sample Input 1

[1, 2, 3, 5, 7]

13

Sample Output 1

3

Sample Input 2

[34, 32, 37, 38, 40]

10

Sample Output 2





Product of Array Items

Given an array

integers, write a JS program to get the product of the integers in the given array.Input

  • The input will be a single line containing an array integers

Output

  • The output should be a single line string containing the product as shown in sample outputs

Sample Input 1

[1, 2, 3]

Sample Output 1

1 * 2 * 3 = 6

Sample Input 2

[-1, -2, -3]

Sample Output 2

-1 * -2 * -3 = -6




Replacing Array Item

Given an array

myArray, targetItem, and a replaceItem, write a JS program to replace the targetItem with the given replaceItem in myArray. If myArray consists of more than one targetItem replace the first occurrence.Input

  • The first line of input contains an array myArray
  • The second line of input contains a targetItem
  • The third line of input contains a replaceItem

Output

  • The output should be an array containing the replaced item.

Sample Input 1

[1, 2, 3, "four", 5, 6]

"four"

4

Sample Output 1

[ 1, 2, 3, 4, 5, 6 ]

Sample Input 2

[22, 44, 88, 352, 352]

352

176

Sample Output 2

[ 22, 44, 88, 176, 352 ]




Squares of Array Items

Given an array

myArray, write a JS program to get the squares of each item in the given myArray.Input

  • The input will be a single line containing an array myArray
  • myArray consists of numbers and arrays

Output

  • The output should be an array containing the square of each item

Sample Input 1

[[1, 2], [3, 4], [5, 6]]

Sample Output 1

[ [ 1, 4 ], [ 9, 16 ], [ 25, 36 ] ]

Sample Input 2

[12, [24], 36, [48, 60]]

Sample Output 2

[ 144, [ 576 ], 1296, [ 2304, 3600 ] ]




how to write the program for polynomials


how to write the matrix rotation program


how to find out the antidiagonal matrix


given string in camel case and convert the camel case to snake case


How to convert the string fro camel case to snake case


The Bone Jour Dog Day Care Centre charges clients a daily rate that is based on both the size of the dog and number of days per month in a client’s contract. The following tableshows the daily rates.Prompt the user to enter a dog’s weight and number of days per month needing care, then calculate and display the daily rate and the total for the month (days times the daily rate). Save the file as DogDayCare.java


LATEST TUTORIALS
APPROVED BY CLIENTS