/**
 * Given a list of elements, replace all occurrences of a specific element with a new one.
 *
 * @param elements A list of elements.
 * @param toReplace The element to be replaced.
 * @param replaceWith The element to replace the occurrences.
 * @return The modified list with replaced elements.
 *
 * Example:
 * sliceAndReplaceElements(listOf("apple", "banana", "cherry", "apple"), "apple", "orange")
 * Output: ["orange", "banana", "cherry", "orange"]
 */
fun sliceAndReplaceElements(elements: List<Any>, toReplace: Any, replaceWith: Any): List<Any> {

    val newElements = mutableListOf<Any>()
    for (element in elements) {
        if (element != toReplace) {
            newElements.add(element)
        } else {
            newElements.add(replaceWith)
        }
    }
    return newElements
}
/**
 * Given a list of elements, replace all occurrences of a specific element with a new one.
 *
 * @param elements A list of elements.
 * @param toReplace The element to be replaced.
 * @param replaceWith The element to replace the occurrences.
 * @return The modified list with replaced elements.
 *
 * Example:
 * sliceAndReplaceElements(listOf("apple", "banana", "cherry", "apple"), "apple", "orange")
 * Output: ["orange", "banana", "cherry", "orange"]
 */
fun sliceAndReplaceElements(elements: List<Any>, toReplace: Any, replaceWith: Any): List<Any> {
/**
 * Given a list of elements, replace all occurrences of a specific element with a new one.
 *
 * @param elements A list of elements.
 * @param toReplace The element to be replaced.
 * @param replaceWith The element to replace the occurrences.
 * @return The modified list with replaced elements.
 *
 * Example:
 * sliceAndReplaceElements(listOf("apple", "banana", "cherry", "apple"), "apple", "orange")
 * Output: ["orange", "banana", "cherry", "orange"]
 */
fun sliceAndReplaceElements(elements: List<Any>, toReplace: Any, replaceWith: Any): List<Any> {

    val newElements = mutableListOf<Any>()
    for (element in elements) {
        if (element != toReplace) {
            newElements.add(element)
        } else {
            newElements.add(replaceWith)
        }
    }
    return newElements
}