-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy patharrays.js
More file actions
103 lines (80 loc) · 1.95 KB
/
arrays.js
File metadata and controls
103 lines (80 loc) · 1.95 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const getNthElement = (index, array) => {
return array[index];
};
const arrayToCSVString = array => {
// your code here
return array.join(",")
};
const csvStringToArray = string => {
// your code here
return string.split(",");
};
const addToArray = (element, array) => {
array.push(element);
};
const addToArray2 = (element, array) => {
// your code here
const newArray = array.push(element)
console.log(newArray);
};
const removeNthElement = (index, array) => {
// your code here
return array.splice(index, 1);
};
const numbersToStrings = numbers => {
// your code here
return numbers.toString().split(',')
};
const uppercaseWordsInArray = strings => {
// your code here
return strings.map(name => name.toUpperCase());
};
const reverseWordsInArray = strings => {
// your code here
return strings.map(item => item.split('').reverse().join(''));
};
const onlyEven = numbers => {
// your code here
return numbers.filter(item => item % 2 === 0);
};
const removeNthElement2 = (index, array) => {
// your code here
};
const elementsStartingWithAVowel = strings => {
// your code here
const vowels = ['a','e','i','o','u'];
return vowels.map(function(vowel) {
return strings.find(function(string) {
return string.toLowerCase().charAt(0) === vowel;
});
});
};
const removeSpaces = string => {
// your code here
return string.replace(/\s+/g, '')
};
const sumNumbers = numbers => {
// your code here
return numbers.reduce((acc, curr) => acc + curr);
};
const sortByLastLetter = strings => {
// your code here
return strings.sort((a, b) => a.charCodeAt(a.length - 1) - b.charCodeAt(b.length - 1));
};
module.exports = {
getNthElement,
arrayToCSVString,
csvStringToArray,
addToArray,
addToArray2,
removeNthElement,
numbersToStrings,
uppercaseWordsInArray,
reverseWordsInArray,
onlyEven,
removeNthElement2,
elementsStartingWithAVowel,
removeSpaces,
sumNumbers,
sortByLastLetter
};