-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy path9-array.js
More file actions
28 lines (20 loc) · 851 Bytes
/
9-array.js
File metadata and controls
28 lines (20 loc) · 851 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
'use strict';
/* Collections: Array, Hash (Object)
Implement phone book using array of records.
- Define Array of objects with two fields: `name` and `phone`.
Object example: `{ name: 'Marcus Aurelius', phone: '+380445554433' }`.
- Implement function `findPhoneByName` with signature
`findPhoneByName(name: string): string`. Returning phone from that object
where field `name` equals argument `name`. Use `for` loop for this search. */
const phonebook = [
{ name: 'Marcus Aurelius', phone: '+380445554433' },
{ name: 'Denis Vasilenko', phone: '+79673196182' },
{ name: 'Milane Ganeeva', phone: '+78934832938' },
];
const findPhoneByName = (name) => {
for (const user of phonebook) {
if (user.name === name) return user.phone;
}
};
console.log(findPhoneByName('Denis Vasilenko'));
module.exports = { phonebook, findPhoneByName };