/**
 * Given a text string, a start index, an end index and a new value,
 * this function replaces the text elements within the specified slice with the new value.
 *
 * @param text The original text string.
 * @param startIndex The index at which the slice starts (inclusive).
 * @param endIndex The index at which the slice ends (exclusive).
 * @param newValue The new value to replace the slice elements with.
 * @return The modified text string.
 * @throws IndexOutOfBoundsException If the start index or end index is out of range.
 */
fun changeElements(text: String, startIndex: Int, endIndex: Int, newValue: String): String {

    if (startIndex < 0 || endIndex > text.length) {
        throw IndexOutOfBoundsException("Index out of range!")
    }
    
    return text.substring(0, startIndex) + newValue + text.substring(endIndex)
}

// Exercise:
/**
 * Given a text string, a start index, an end index and a new value,
 * this function replaces the text elements within the specified slice with the new value.
 *
 * @param text The original text string.
 * @param startIndex The index at which the slice starts (inclusive).
 * @param endIndex The index at which the slice ends (exclusive).
 * @param newValue The new value to replace the slice elements with.
 * @return The modified text string.
 * @throws IndexOutOfBoundsException If the start index or end index is out of range.
 */
fun changeElements(text: String, startIndex: Int, endIndex: Int, newValue: String): String {
/**
 * Given a text string, a start index, an end index and a new value,
 * this function replaces the text elements within the specified slice with the new value.
 *
 * @param text The original text string.
 * @param startIndex The index at which the slice starts (inclusive).
 * @param endIndex The index at which the slice ends (exclusive).
 * @param newValue The new value to replace the slice elements with.
 * @return The modified text string.
 * @throws IndexOutOfBoundsException If the start index or end index is out of range.
 */
fun changeElements(text: String, startIndex: Int, endIndex: Int, newValue: String): String {

    if (startIndex < 0 || endIndex > text.length) {
        throw IndexOutOfBoundsException("Index out of range!")
    }
    
    return text.substring(0, startIndex) + newValue + text.substring(endIndex)
}

// Exercise: