forked from jobtrek/dev-24-javascript-exercise-ex-js-empty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrays.js
43 lines (37 loc) · 1.16 KB
/
arrays.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @param {array<string>} array An array containing words and sentences
* @return {array<string>} An array with all words isolated, and with empty strings removed
*/
export function splitAllStringsByWordAndFilterEmptyOnes(array) {
// Write your code here
return array
.join(' ')
.split(' ')
.filter(word => word.length > 0);
}
/**
* @param {*[]} array1
* @param {*[]} array2
* @return {*[]} return an array containing all elements from the two given arrays
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax
*/
export function concatenateArrays(array1, array2) {
// Write your code here
return [].concat(array1, array2);
}
/**
* @param {array} array an array of arbitrary elements
* @param {number} index where you need to replace the element in the array
* @param {...*} newElements
* @return {array<*>} A new array, sorted, **the original array should not be modified**
*/
export function replaceElementsInArrayAtAGivenPlace(
array,
index,
...newElements
) {
// Write your code here
const newArray = [...array];
newArray.splice(index, newElements.length, ...newElements);
return newArray;
}