Question: Create the username portion of a registration system that requires all usernames are unique. If a new user requests a name that is already

Create the username portion of a registration system that requires all usernames are unique. If a new user requests a name thSample Case 0 Sample Input 4 alex xylos alex alan Sample Output 0 alex xylos alex1 alan Explanation 0 There are 4 usernames rExplanation Each of the users has a different username so no modifications are needed. Sample Case 2 Sample Input 4 john john

use strict; . 1 26 Complete the usernames System function below. 27 28 The function is expected to return a STRING_ARRAY 2

Create the username portion of a registration system that requires all usernames are unique. If a new user requests a name that is already used, an integer should be added to the end of the username to make it unique. The numbering begins with 1 and is incremented by 1 for each new instance per username. As an example, if username requests were for [bob, alice, bob, alice, bob, alice], the system should assign usernames [bob, alice, bob1, alice1, bob2, alice2]. Given a list of username requests in the order given, process all requests and return an array of the usernames as assigned by the function. Function Description Complete the function usernamesSystem in the editor below. The function must return an array of usernames in the order assigned. usernamesSystem has the following parameter(s): u[u[0]....u[n-1]]: an array of username strings in the order requested Constraints 1n 104 1 lu[i] 20 u[i] contains only lowercase English letters in the range ascii[a-z]. Input Format for Custom Testing Input from stdin will be processed as follows and passed to the function. The first line contains n, the number of strings in array u. The next n lines each contain a string u[i] representing a username request in the order received. Sample Case 0 Sample Input 4 alex xy los alex alan Sample Output 0 alex xylos alex1 alan Explanation 0 There are 4 usernames requested. Each username is unique with the exception of "alex": u[2] = "alex" must be modified. Since this is the first duplicate request for the username "alex", the function should insert "alex1" to that position in u. Sample Case 1 Sample Input 2 bob alice Sample Output 1 bob alice Explanation 1 Each of the users has a different username so no modifications are needed. Explanation 1 Each of the users has a different username so no modifications are needed. Sample Case 2 Sample Input 4 john john tom john Sample Output 2 john john1 tom john2 Explanation 2 Three instances of "john" require that usernames "john", "john1" and "john2" be inserted into the array at the appropriate positions. 1 'use strict'; 26 /* 27 28 29 30 31 32 33 34 35 * Complete the 'usernames System' function below. * The function is expected to return a STRING_ARRAY. * The function accepts STRING_ARRAY u as parameter. */ function usernames System (u) { // Write your code here

Step by Step Solution

3.44 Rating (151 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To solve this problem we need a system to ensure each username request is unique by appending a numb... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!