/**
 * Exercise: Modifying elements in a name using negative indexing
 *
 * Given a name, the index of a character, and a replacement character, modify the name by replacing the character at the specified index with the replacement character.
 *
 * @param name The name to be modified
 * @param index The index of the character to be replaced. Negative indexing is allowed.
 * @param replacement The character to replace the one at the specified index
 * @return The modified name
 *
 * Example:
 * modifyName("Jennifer", -3, "x")
 * Returns:
 * "Jenxifer"
 */
fun modifyName(name: String, index: Int, replacement: Char): String {

    // Check if the provided index is within the bounds of the name
    if (Math.abs(index) > name.length) {
        throw IndexOutOfBoundsException("Index is out of range.")
    }

    // Split the name into two parts: before and after the specified index
    val nameBefore = name.substring(0, index)
    val nameAfter = name.substring(index + 1)

    // Construct the modified name by combining the before, replacement, and after parts
    val modifiedName = nameBefore + replacement + nameAfter

    return modifiedName
}
/**
 * Exercise: Modifying elements in a name using negative indexing
 *
 * Given a name, the index of a character, and a replacement character, modify the name by replacing the character at the specified index with the replacement character.
 *
 * @param name The name to be modified
 * @param index The index of the character to be replaced. Negative indexing is allowed.
 * @param replacement The character to replace the one at the specified index
 * @return The modified name
 *
 * Example:
 * modifyName("Jennifer", -3, "x")
 * Returns:
 * "Jenxifer"
 */
fun modifyName(name: String, index: Int, replacement: Char): String {
/**
 * Exercise: Modifying elements in a name using negative indexing
 *
 * Given a name, the index of a character, and a replacement character, modify the name by replacing the character at the specified index with the replacement character.
 *
 * @param name The name to be modified
 * @param index The index of the character to be replaced. Negative indexing is allowed.
 * @param replacement The character to replace the one at the specified index
 * @return The modified name
 *
 * Example:
 * modifyName("Jennifer", -3, "x")
 * Returns:
 * "Jenxifer"
 */
fun modifyName(name: String, index: Int, replacement: Char): String {

    // Check if the provided index is within the bounds of the name
    if (Math.abs(index) > name.length) {
        throw IndexOutOfBoundsException("Index is out of range.")
    }

    // Split the name into two parts: before and after the specified index
    val nameBefore = name.substring(0, index)
    val nameAfter = name.substring(index + 1)

    // Construct the modified name by combining the before, replacement, and after parts
    val modifiedName = nameBefore + replacement + nameAfter

    return modifiedName
}