Skip to content

Commit 4f47618

Browse files
Merge pull request #246 from Yash0605/js-codes
Added the code for whats in the name problem under beginner section
2 parents 4f4977e + 4d7b3d4 commit 4f47618

File tree

1 file changed

+49
-0
lines changed
  • Beginner/Whats in the Name (NITIKA)

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
process.stdin.resume();
2+
process.stdin.setEncoding("utf8");
3+
4+
let data = "";
5+
6+
process.stdin.on("data", function (chunk) {
7+
data += chunk.toString();
8+
});
9+
10+
process.stdin.on("end", function () {
11+
runTestCases();
12+
});
13+
14+
function runTestCases() {
15+
let lines = data.split("\n"); // Getting all the inputs
16+
let length = 0;
17+
const t = parseInt(lines[length++]); // Getting the number of test cases
18+
19+
for (let i = 0; i < t; i++) {
20+
const name = lines[length++];
21+
const partsOfName = name.split(" ");
22+
23+
if (partsOfName.length === 1) {
24+
const lastName = partsOfName[0].toLowerCase();
25+
console.log(lastName.charAt(0).toUpperCase() + lastName.slice(1));
26+
} else if (partsOfName.length === 2) {
27+
const firstName = partsOfName[0];
28+
const lastName = partsOfName[1].toLowerCase();
29+
console.log(
30+
firstName.charAt(0).toUpperCase() +
31+
". " +
32+
lastName.charAt(0).toUpperCase() +
33+
lastName.slice(1)
34+
);
35+
} else {
36+
const firstName = partsOfName[0];
37+
const middleName = partsOfName[1];
38+
const lastName = partsOfName[2].toLowerCase();
39+
console.log(
40+
firstName.charAt(0).toUpperCase() +
41+
". " +
42+
middleName.charAt(0).toUpperCase() +
43+
". " +
44+
lastName.charAt(0).toUpperCase() +
45+
lastName.slice(1)
46+
);
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)