/**
 * Given a list of emails and a domain, return a list of all emails that belong to that domain.
 *
 * @param emails A list of email addresses.
 * @param domain A domain name to filter the emails.
 * @return A list of email addresses belonging to the specified domain.
 *
 * Example:
 * emails = ['john@gmail.com', 'alice@yahoo.com', 'peter@hotmail.com', 'david@gmail.com']
 * filterEmails(emails, 'gmail.com') -> ['john@gmail.com', 'david@gmail.com']
 */
fun filterEmails(emails: List<String>, domain: String): List<String> {

    val filteredEmails = mutableListOf<String>()

    // Iterate over each email in the list
    for (email in emails) {
        // Extract the domain from the email address
        val emailDomain = email.split('@')[1]

        // Check if the email belongs to the specified domain
        if (emailDomain == domain) {
            filteredEmails.add(email)
        }
    }

    return filteredEmails
}
/**
 * Given a list of emails and a domain, return a list of all emails that belong to that domain.
 *
 * @param emails A list of email addresses.
 * @param domain A domain name to filter the emails.
 * @return A list of email addresses belonging to the specified domain.
 *
 * Example:
 * emails = ['john@gmail.com', 'alice@yahoo.com', 'peter@hotmail.com', 'david@gmail.com']
 * filterEmails(emails, 'gmail.com') -> ['john@gmail.com', 'david@gmail.com']
 */
fun filterEmails(emails: List<String>, domain: String): List<String> {
/**
 * Given a list of emails and a domain, return a list of all emails that belong to that domain.
 *
 * @param emails A list of email addresses.
 * @param domain A domain name to filter the emails.
 * @return A list of email addresses belonging to the specified domain.
 *
 * Example:
 * emails = ['john@gmail.com', 'alice@yahoo.com', 'peter@hotmail.com', 'david@gmail.com']
 * filterEmails(emails, 'gmail.com') -> ['john@gmail.com', 'david@gmail.com']
 */
fun filterEmails(emails: List<String>, domain: String): List<String> {

    val filteredEmails = mutableListOf<String>()

    // Iterate over each email in the list
    for (email in emails) {
        // Extract the domain from the email address
        val emailDomain = email.split('@')[1]

        // Check if the email belongs to the specified domain
        if (emailDomain == domain) {
            filteredEmails.add(email)
        }
    }

    return filteredEmails
}