-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq32.ts
More file actions
32 lines (27 loc) · 1.41 KB
/
q32.ts
File metadata and controls
32 lines (27 loc) · 1.41 KB
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
// Checking Usernames: Do the following to create a program that simulates how websites ensure that everyone has a unique username.
// • Make a list of five or more usernames called current_users.
// • Make another list of five usernames called new_users. Make sure one or two of the new usernames are also in the current_users list.
// • Loop through the new_users list to see if each new username has already been used. If it has, print a message that the person will need to enter a new username. If a username has not been used, print a message saying that the username is available.
// • Make sure your comparison is case insensitive. If 'John' has been used, 'JOHN' should not be accepted.
export default function q32(){
// Make a list of current users
const current_users: string[] = ['john21', 'jane', 'bob', 'alice', 'mark'];
// Make a list of new users
const new_users: string[] = ['jim23', 'JOHN21', 'tom', 'sarah', 'bob'];
// Loop through new users and check if they're unique
for (let i = 0; i < new_users.length; i++) {
let isUnique = true;
for (let j = 0; j < current_users.length; j++) {
if (new_users[i].toLowerCase() === current_users[j].toLowerCase()) {
isUnique = false;
break;
}
}
if (isUnique) {
console.log(`${new_users[i]} is available`);
} else {
console.log(`${new_users[i]} is not available, please enter a new username`);
}
}
}
q32();