-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray3.js
More file actions
21 lines (15 loc) · 853 Bytes
/
array3.js
File metadata and controls
21 lines (15 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Today I'd like you to write a function that:
// takes in a given array of strings and move any entries containing the letter 'a' to the front
// then move any remaining entries that have over 3 characters to the back
// please preserve the relative order of entries within their given category
// Example:
myArr = ['hi', 'hello', 'howdy', 'hola', 'hej', 'hallo', 'heyyy']
// // move things around
// => ['hola', 'hallo', 'hi', 'hej', 'hello', 'howdy', 'heyyy']
function moveThings(myArr){
let wordsIncludeA= myArr.filter(word => word.includes("a"))
let wordsGreaterThanThree = myArr.filter(word => word.length > 3 && !word.includes("a"))
let wordsLessThanThree = myArr.filter(word => word.length <= 3 && !word.includes("a"))
return wordsIncludeA.concat(wordsLessThanThree, wordsGreaterThanThree)
}
console.log(moveThings(myArr))