* fix: restructure certifications guide articles * fix: added 3 dashes line before prob expl * fix: added 3 dashes line before hints * fix: added 3 dashes line before solutions
941 B
941 B
title
| title |
|---|
| Copy Array Items Using slice() |
Copy Array Items Using slice()
- the
slice()function must be used to return an array consisting of onlywarmandsunny. - Therefore, two parameters must be passed to the
slice()function. The first parameter must be the index you would like the substring to start at. The second parameter must be the index at which the substring ends. - Note: The second parameter will end the substring at that exact index.
Example:
return arr.slice(1, 4);
/* This will return a substring consisting of indexs [1,2,3]
Note: arr[4] is NOT included. */
Solutions
Solution 1 (Click to Show/Hide)
function forecast(arr) {
// change code below this line
return arr.slice(2, 4);
}
// do not change code below this line
console.log(
forecast(["cold", "rainy", "warm", "sunny", "cool", "thunderstorms"])
);