Skip to content

Commit db57186

Browse files
committed
First example
1 parent 27371cf commit db57186

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

JavaScript/1-basics.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
const SALUTATION = 'Ave';
4+
5+
const COLORS = [
6+
'black', 'red', 'green', 'yellow',
7+
'blue', 'magenta', 'cyan', 'white'
8+
];
9+
10+
const colorer = (s, color) => `\x1b[3${color}m${s}\x1b[0m`;
11+
12+
const colorize = name => {
13+
const letters = name.split('');
14+
let color = 1;
15+
let res = '';
16+
for (const letter of letters) {
17+
res += colorer(letter, color++);
18+
if (color > COLORS.length) color = 1;
19+
}
20+
return res;
21+
};
22+
23+
const greetings = name => (
24+
name.includes('Augustus') ?
25+
`${SALUTATION}, ${colorize(name)}!` :
26+
`Hello, ${name}!`
27+
);
28+
29+
const fullName = 'Marcus Aurelius Antoninus Augustus';
30+
console.log(greetings(fullName));
31+
32+
const shortName = 'Marcus Aurelius';
33+
console.log(greetings(shortName));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy