Day 28: RegEx, Patterns, and Intro to Databases

  • + 0 comments

    TypeScript/JavaScript

    function printArray<T>(array: T[]): void {
        for (let i = 0; i < array.length; i++) {
            console.log(array[i]);
        }
    }
    
    function main() {
        const N: number = parseInt(readLine().trim(), 10);
        const arrPerson: string[] = new Array();
        const regexGmail: RegExp = /^[a-z.]+@gmail\.com$/;
    
        for (let NItr: number = 0; NItr < N; NItr++) {
            const firstMultipleInput: string[] = readLine().replace(/\s+$/g, '').split(' ');
    
            const firstName: string = firstMultipleInput[0];
    
            const emailID: string = firstMultipleInput[1];
    
            if (emailID.match(regexGmail)) {
                arrPerson.push(firstName);
            }
        }
    
        arrPerson.sort();
        printArray(arrPerson);
    }