/**
 * Exercise:
 * The input for this exercise is a string representation of an actor or actress.
 * Your task is to write a function that creates a tuple containing the actor's first name, middle initial, and last name.
 * The input string will be in the format "Last Name, First Name Middle Initial" with no leading or trailing spaces.
 *
 * Example:
 * Input: "Smith, John D"
 * Output: ("John", "D", "Smith")
 *
 * Note:
 * - If the actor or actress does not have a middle name or initial, the middle initial in the tuple should be an empty string.
 * - The function should return null if the input format is invalid.
 * - You can assume that the input string will always have a last name and a first name.
 * - The input string can include upper and lower case letters.
 */
fun createActorTuple(actorStr: String): Triple<String, String, String>? {

    // Trim leading or trailing spaces
    val actorStrTrimmed = actorStr.trim()

    // Split the string into last name, first name, and middle initial
    val nameParts = actorStrTrimmed.split(", ")
    if (nameParts.size != 2) {
        return null
    }
    val lastName = nameParts[0]
    val firstNameParts = nameParts[1].split(" ")
    if (firstNameParts.size < 2) {
        return Triple(firstNameParts[0], "", lastName)
    }
    val firstName = firstNameParts[0]
    val middleInitial = firstNameParts[1]
    return Triple(firstName, middleInitial, lastName)
}
/**
 * Exercise:
 * The input for this exercise is a string representation of an actor or actress.
 * Your task is to write a function that creates a tuple containing the actor's first name, middle initial, and last name.
 * The input string will be in the format "Last Name, First Name Middle Initial" with no leading or trailing spaces.
 *
 * Example:
 * Input: "Smith, John D"
 * Output: ("John", "D", "Smith")
 *
 * Note:
 * - If the actor or actress does not have a middle name or initial, the middle initial in the tuple should be an empty string.
 * - The function should return null if the input format is invalid.
 * - You can assume that the input string will always have a last name and a first name.
 * - The input string can include upper and lower case letters.
 */
fun createActorTuple(actorStr: String): Triple<String, String, String>? {
/**
 * Exercise:
 * The input for this exercise is a string representation of an actor or actress.
 * Your task is to write a function that creates a tuple containing the actor's first name, middle initial, and last name.
 * The input string will be in the format "Last Name, First Name Middle Initial" with no leading or trailing spaces.
 *
 * Example:
 * Input: "Smith, John D"
 * Output: ("John", "D", "Smith")
 *
 * Note:
 * - If the actor or actress does not have a middle name or initial, the middle initial in the tuple should be an empty string.
 * - The function should return null if the input format is invalid.
 * - You can assume that the input string will always have a last name and a first name.
 * - The input string can include upper and lower case letters.
 */
fun createActorTuple(actorStr: String): Triple<String, String, String>? {

    // Trim leading or trailing spaces
    val actorStrTrimmed = actorStr.trim()

    // Split the string into last name, first name, and middle initial
    val nameParts = actorStrTrimmed.split(", ")
    if (nameParts.size != 2) {
        return null
    }
    val lastName = nameParts[0]
    val firstNameParts = nameParts[1].split(" ")
    if (firstNameParts.size < 2) {
        return Triple(firstNameParts[0], "", lastName)
    }
    val firstName = firstNameParts[0]
    val middleInitial = firstNameParts[1]
    return Triple(firstName, middleInitial, lastName)
}