0
0
Kotlinprogramming~30 mins

Take, drop, and chunked in Kotlin - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Take, Drop, and Chunked in Kotlin
📖 Scenario: You are working on a Kotlin program that processes a list of daily temperatures recorded over a week. You want to extract parts of this data to analyze specific days and group days into smaller chunks.
🎯 Goal: Build a Kotlin program that uses take, drop, and chunked functions to manipulate a list of temperatures.
📋 What You'll Learn
Create a list of exactly 7 temperatures as integers
Create a variable to hold the number of days to take from the start
Use take to get the first few temperatures
Use drop to skip the first few temperatures
Use chunked to split the list into groups of 3
Print the results exactly as specified
💡 Why This Matters
🌍 Real World
Processing lists of data like temperatures, sales, or scores is common. Using <code>take</code>, <code>drop</code>, and <code>chunked</code> helps you focus on parts of the data or group it for easier analysis.
💼 Career
Many programming jobs require working with lists or arrays. Knowing how to extract and group data efficiently is a useful skill for data analysis, app development, and backend programming.
Progress0 / 4 steps
1
Create the temperature list
Create a list called temperatures with these exact integer values: 23, 25, 22, 20, 24, 26, 21.
Kotlin
Need a hint?

Use listOf to create a list with the exact numbers.

2
Set the number of days to take
Create an integer variable called daysToTake and set it to 4.
Kotlin
Need a hint?

Use val daysToTake = 4 to create the variable.

3
Use take, drop, and chunked
Create three variables: firstDays using temperatures.take(daysToTake), afterDays using temperatures.drop(daysToTake), and chunkedDays using temperatures.chunked(3).
Kotlin
Need a hint?

Use the take, drop, and chunked functions exactly as shown.

4
Print the results
Print firstDays, afterDays, and chunkedDays each on its own line using println.
Kotlin
Need a hint?

Use println to print each variable on its own line.