-
Notifications
You must be signed in to change notification settings - Fork 0
/
07_copyWithSlice.js
26 lines (20 loc) · 918 Bytes
/
07_copyWithSlice.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copy Array Items Using slice()
/* Since the slice() method returns an array of
the items it extracted, these values can be assigned
to a new array leaving the original source untouched */
let weatherConditions = ['rain', 'snow', 'sleet', 'hail', 'clear'];
let todaysWeather = weatherConditions.slice(1, 3);
console.log(weatherConditions, todaysWeather);
// ['rain', 'snow', 'sleet', 'hail', 'clear'] ['snow', 'sleet']
/* We have defined a function, forecast, that takes an array
as an argument. Modify the function using slice() to
extract information from the argument array and return a
new array that contains the string elements warm and
sunny. */
function forecast(arr) {
// Only change code below this line
let idealForecast = arr.slice(2, 4);
return idealForecast;
}
// Only change code above this line
console.log(forecast(['cold', 'rainy', 'warm', 'sunny', 'cool', 'thunderstorms']));