-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathremoveEvenStrings.js
More file actions
44 lines (37 loc) · 888 Bytes
/
removeEvenStrings.js
File metadata and controls
44 lines (37 loc) · 888 Bytes
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
/**
* Takes in an array of strings and returns a new array that contains only the strings
* that have an odd number of characters.
*
* @param {string[]} arr - The input array of strings
* @returns {string[]} - A new array with the strings in arr that have an odd number of characters
*
* ex: removeEvenStrings(["a", "bb", "ccc", "dddd", "eeeee"])
* returns: ["a", "ccc", "eeeee"]
*
* ex: removeEvenStrings(["the", "cat", "is", "gray"])
* returns: ["the", "cat"]
*
* ex: removeEvenStrings(["four"])
* returns: []
*
* ex: removeEvenStrings([])
* returns: []
*/
function removeEvenStrings(arr) {
return arr.filter(str => str.length % 2 === 1)
}
let arr = ([
"The",
"only",
"thing",
"we",
"have",
"to",
"fear",
"is",
"fear",
"itself",
])
// console.log(arr[0].length)
console.log(removeEvenStrings(arr))
module.exports = removeEvenStrings