programming_language: java

code:
public class Calculator {
    public static int add(int a, int b) {
        return a + b;
    }
    public static int multiply(int a, int b) {
        return a * b;
    }
}

code_description: Synthetic java code snippet demonstrating common patterns

difficulty_level: beginner

dataset_source: synthetic

author: synthetic


programming_language: javascript

code:
const debounce = (func, delay) => {
    let timeoutId;
    return (...args) => {
        clearTimeout(timeoutId);
        timeoutId = setTimeout(() => func(...args), delay);
    };
}

code_description: Synthetic javascript code snippet demonstrating common patterns


programming_language: python

code:
def binary_search(arr, target):
    left, right = 0, len(arr) - 1
    while left <= right:
        mid = (left + right) // 2
        if arr[mid] == target:
            return mid
        elif arr[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return -1

code_description: Synthetic python code snippet demonstrating common patterns


code:
def fibonacci(n):
    if n <= 1:
        return n
    return fibonacci(n-1) + fibonacci(n-2)