JavaScript 💯 || Accepted ✅
Arithmetic Subarrays \uD83D\uDD25\n> ### Certainly! Below is a JavaScript function that takes an array nums and two arrays of range queries l and r, and returns
# Arithmetic Subarrays \uD83D\uDD25\n> ### Certainly! Below is a JavaScript function that takes an array nums and two arrays of range queries l and `r`, and returns `a` boolean array answer based on whether the subarrays satisfy the conditions of being an arithmetic sequence:\n- This function iterates through the given range queries, extracts the corresponding subarrays from the `nums` array, sorts them, and then checks if the sorted subarray is an arithmetic sequence. The result is stored in the `result` array, which is then returned.\n```\nfunction checkArithmeticSubarrays(nums, l, r) {\n    const result = [];\n\n    for (let i = 0; i < l.length; i++) {\n        const start = l[i];\n        const end = r[i];\n\n        // Extract the subarray\n        const subarray = nums.slice(start, end + 1);\n\n        // Sort the subarray\n        subarray.sort((a, b) => a - b);\n\n        // Check if the sorted subarray is arithmetic\n        const commonDifference = subarray[1] - subarray[0];\n        let isArithmetic = true;\n        for (let j = 2; j < subarray.length; j++) {\n            if (subarray[j] - subarray[j - 1] !== commonDifference) {\n                isArithmetic = false;\n                break;\n            }\n        }\n\n        result.push(isArithmetic);\n    }\n\n    return result;\n}\n\n// Example usage:\nconst nums = [1, 3, 5, 7, 9];\nconst l = [0, 0, 2];\nconst r = [2, 4, 4];\n\nconst answer = checkArithmeticSubarrays(nums, l, r);\nconsole.log(answer); // Output: [true, false, true]\n\n```
['JavaScript']