forked from AustinCodingAcademy/javascript-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04basicFilter.js
More file actions
33 lines (27 loc) · 921 Bytes
/
04basicFilter.js
File metadata and controls
33 lines (27 loc) · 921 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
'use script';
// Use Array#filter to write a function called getShortMessages.
//
// getShortMessages takes an array of objects with '.message' properties and returns an array of messages that are less than < 50 characters long.
//
// The function should return an array containing the messages themselves, without their containing object.
// const getShortMessages = (messages) => {
// messages.filter(obj => obj.message.length < 50))
// };
// }
// function getShortMessages(messages) {
//
// let shortMessage = messages.filter(function(shorten) {
// if (shorten.message.length < 50) {
// return true;
// }
// });
//
// return shortMessage.map(function(shorten) {
// return shorten.message;
// })
// }
module.exports = getShortMessages
const getShortMessages = (messages) => {
return messages.map(obj => obj.message).filter(msg => msg.length < 50);
}
module.exports = getShortMessages