Random Sampling
[Source | Tests]
Operations for randomly selecting k elements without replacement from a sequence or collection.
Use these methods for sampling multiple elements from a collection, optionally maintaining the relative order of the elements. Each method has an overload that takes a RandomNumberGenerator as a parameter.
What is the output of the following list operationaList = [10, 20, 30, 40, 50, 60, 70, 80]print(aList[2:5])print(aList[:4])print(aList[3:])
The correct result doesn't make sense. Please explain why its correct.
Here is the description of the challenge.
Challenge Task 4 of 4
Great job so far! Clearly you know how to add and read items from the array so in this challenge let's try getting rid of a value.
For this task, remove the 6th item from the array and assign the result to a constant named discardedValue.
To remove an item, use the method removeAtIndex() and put the index number in between parentheses that you want to remove.
MY ANSWER:
I'm removing 6th item from the array, which is 60 then when I'm assigning result to a constant named discardedValue and this is where things are getting tricky. I checked what "discardedValue" returns and its not 60 it's the following number in the array 70. Why is it the right answer? I'm suppose to assign result to a constant, which is suppose to be the same result of arrayOfInts.removeAtIndex(5) 60. I'm confused.