Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Solution Review: Array of Integers

Sumit Rawal answered on May 23, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • Solution Review: Array of Squares
  • int findSmallestInt(List<int> arr) { // Code here int small = arr[0]; for (int i = 1; i < arr.length; i++){ if (arr[i] < small) { small = arr[i]; } } return small; } comment this code

  • Solution Review: Array of Integers

    0

    Task

    In this challenge, you were provided a range of numbers. Using the range of numbers, you had to create and populate an array. The final array could only consist of even multiples of 3.

    Solution

    Let’s go over the solution step-by-step.

    The first thing you had to do was create an array, let’s call it array1, using the range method to which you had to pass minRange and maxRange.

    val array1 = Array.range(minRange, maxRange)

    Next, you had to create a new array, let’s call it array2, by multiplying the elements of array1 with 3. This could be done using the map method.

    val array2 = array1.map(_ * 3)

    Finally, the last step required you to create yet another array, finalArray, by filtering out the even numbers from array2. This could be done using the filter method.

    val finalArray = array2.filter(_ % 2 == 0)

    You can find the complete solution below:

    You were required to write the code from line 3 till line 5. 

    Popularity 1/10 Helpfulness 1/10 Language scala
    Source: Grepper
    Tags: scala solution
    Link to this answer
    Share Copy Link
    Contributed on May 23 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.