-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path7-fixed.js
More file actions
30 lines (24 loc) · 763 Bytes
/
7-fixed.js
File metadata and controls
30 lines (24 loc) · 763 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
'use strict';
const timers = require('node:timers/promises');
const length = async (line) => {
await timers.setTimeout(100);
if (line.trim() === '') throw new Error('Just spaces');
return line.length;
};
const checkType = async (line) => {
await timers.setTimeout(100);
if (line === undefined) throw new Error('Argument is undefined');
if (typeof line !== 'string') throw new Error('Argument is not a string');
if (line === '') throw new Error('Argument is empty string');
};
const getLength = async (line) => {
await timers.setTimeout(100);
await checkType(line);
return await length(line);
};
const main = async () => {
const line = 'Hello World!';
const length = await getLength(line);
console.log({ line, length });
};
main();