Извлечение элементов массива больше «m» и меньше «n» на различных языках программирования

Чтобы извлечь все элементы из заданного массива, которые больше «m» и меньше «n», вы можете использовать несколько методов на разных языках программирования. Вот несколько примеров:

  1. Python:

    def extract_elements(array, m, n):
    result = [x for x in array if m < x < n]
    return result
    # Example usage
    array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    m = 3
    n = 7
    output = extract_elements(array, m, n)
    print(output)  # Output: [4, 5, 6]
  2. JavaScript:

    function extractElements(array, m, n) {
    const result = array.filter(x => m < x && x < n);
    return result;
    }
    // Example usage
    const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    const m = 3;
    const n = 7;
    const output = extractElements(array, m, n);
    console.log(output);  // Output: [4, 5, 6]
  3. Java:

    import java.util.ArrayList;
    import java.util.List;
    public class ArrayExtractor {
    public static List<Integer> extractElements(int[] array, int m, int n) {
        List<Integer> result = new ArrayList<>();
        for (int x : array) {
            if (m < x && x < n) {
                result.add(x);
            }
        }
        return result;
    }
    // Example usage
    public static void main(String[] args) {
        int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        int m = 3;
        int n = 7;
        List<Integer> output = extractElements(array, m, n);
        System.out.println(output);  // Output: [4, 5, 6]
    }
    }