Write a JavaScript function/code that prints the first k and the last k elements from an array of numbers.
The input comes as array of number elements:
-
The first element represents the number k
-
All other elements are from the array that needs to be processed.
Examples:
Input:
[2, 7, 8, 9]
Output:
7 8
8 9
Input:
[3, 6, 7, 8, 9]
Output:
6 7 8
7 8 9
The output is printed on the console on two lines:
-
On the first line print the first k elements, separated by space.
-
On the second line print the last k elements, separated by space.