diff --git "a/data/js/data/humanevalbugs.jsonl" "b/data/js/data/humanevalbugs.jsonl" --- "a/data/js/data/humanevalbugs.jsonl" +++ "b/data/js/data/humanevalbugs.jsonl" @@ -1,164 +1,164 @@ -{"task_id": "JavaScript/0", "prompt": "/* Check if in given list of numbers, are any two numbers closer to each other than\n given threshold.\n >>> hasCloseElements([1.0, 2.0, 3.0], 0.5)\n false\n >>> hasCloseElements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)\n true\n */\nconst hasCloseElements = (numbers, threshold) => {\n", "canonical_solution": " for (let i = 0; i < numbers.length; i++) {\n for (let j = 0; j < numbers.length; j++) {\n if (i != j) {\n let distance = Math.abs(numbers[i] - numbers[j]);\n if (distance < threshold) {\n return true;\n }\n }\n }\n }\n return false;\n}\n\n", "test": "const testHasCloseElements = () => {\n console.assert(hasCloseElements([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.3) === true)\n console.assert(\n hasCloseElements([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.05) === false\n )\n console.assert(hasCloseElements([1.0, 2.0, 5.9, 4.0, 5.0], 0.95) === true)\n console.assert(hasCloseElements([1.0, 2.0, 5.9, 4.0, 5.0], 0.8) === false)\n console.assert(hasCloseElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0], 0.1) === true)\n console.assert(hasCloseElements([1.1, 2.2, 3.1, 4.1, 5.1], 1.0) === true)\n console.assert(hasCloseElements([1.1, 2.2, 3.1, 4.1, 5.1], 0.5) === false)\n}\n\ntestHasCloseElements()\n", "declaration": "\nconst hasCloseElements = (numbers, threshold) => {\n", "example_test": "const testHasCloseElements = () => {\n console.assert(hasCloseElements([1.0, 2.0, 3.0], 0.5) === false)\n console.assert(\n hasCloseElements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3) === true\n )\n}\ntestHasCloseElements()\n", "buggy_solution": " for (let i = 0; i < numbers.length; i++) {\n for (let j = 0; j < numbers.length; j++) {\n if (i != j) {\n let distance = numbers[i] - numbers[j];\n if (distance < threshold) {\n return true;\n }\n }\n }\n }\n return false;\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "hasCloseElements"} -{"task_id": "JavaScript/1", "prompt": "/* Input to this function is a string containing multiple groups of nested parentheses. Your goal is to\n separate those group into separate strings and return the list of those.\n Separate groups are balanced (each open brace is properly closed) and not nested within each other\n Ignore any spaces in the input string.\n >>> separateParenGroups('( ) (( )) (( )( ))')\n ['()', '(())', '(()())']\n */\nconst separateParenGroups = (paren_string) => {\n", "canonical_solution": " var result = [];\n var current_string = [];\n var current_depth = 0;\n\n for (const c of paren_string) {\n if (c == '(') {\n current_depth += 1;\n current_string.push(c);\n } else if (c == ')') {\n current_depth -= 1;\n current_string.push(c);\n if (current_depth == 0) {\n result.push(current_string.join(''));\n current_string = [];\n }\n }\n }\n\n return result;\n}\n\n", "test": "const testSeparateParenGroups = () => {\n console.assert(\n JSON.stringify(separateParenGroups('(()()) ((())) () ((())()())')) ===\n JSON.stringify(['(()())', '((()))', '()', '((())()())'])\n )\n console.assert(\n JSON.stringify(separateParenGroups('() (()) ((())) (((())))')) ===\n JSON.stringify(['()', '(())', '((()))', '(((())))'])\n )\n console.assert(\n JSON.stringify(separateParenGroups('(()(())((())))')) ===\n JSON.stringify(['(()(())((())))'])\n )\n console.assert(\n JSON.stringify(separateParenGroups('( ) (( )) (( )( ))')) ===\n JSON.stringify(['()', '(())', '(()())'])\n )\n}\n\ntestSeparateParenGroups()\n", "declaration": "\nconst separateParenGroups = (paren_string) => {\n", "example_test": "const testSeparateParenGroups = () => {\n console.assert(\n JSON.stringify(separateParenGroups('( ) (( )) (( )( ))')) ===\n JSON.stringify(['()', '(())', '(()())'])\n )\n}\ntestSeparateParenGroups()\n", "buggy_solution": " var result = [];\n var current_string = [];\n var current_depth = 0;\n\n for (const c of paren_string) {\n if (c == '(') {\n current_depth += 1;\n current_string.push(c);\n } else if (c == ')') {\n current_depth -= 1;\n current_string.push(c);\n if (current_depth < 0) {\n result.push(current_string.join(''));\n current_string = [];\n }\n }\n }\n\n return result;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "separateParenGroups"} -{"task_id": "JavaScript/2", "prompt": "/* Given a positive floating point number, it can be decomposed into\n and integer part (largest integer smaller than given number) and decimals\n (leftover part always smaller than 1).\n\n Return the decimal part of the number.\n >>> truncateNumber(3.5)\n 0.5\n */\nconst truncateNumber = (number) => {\n", "canonical_solution": " return number % 1.0;\n}\n\n", "test": "const testTruncateNumber = () => {\n console.assert(truncateNumber(3.5) === 0.5)\n\n console.assert(Math.abs(truncateNumber(1.33) - 0.33) < 1e-6)\n\n console.assert(Math.abs(truncateNumber(123.456 - 0.456) < 1e-6))\n}\n\ntestTruncateNumber()\n", "declaration": "\nconst truncateNumber = (number) => {\n", "example_test": "const testTruncateNumber = () => {\n console.assert(truncateNumber(3.5) === 0.5)\n}\ntestTruncateNumber()\n", "buggy_solution": " return number % 1.0 + 1.0;\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "truncateNumber"} -{"task_id": "JavaScript/3", "prompt": "/* You're given a list of deposit and withdrawal operations on a bank account that starts with\n zero balance. Your task is to detect if at any point the balance of account fallls below zero, and\n at that point function should return true. Otherwise it should return false.\n >>> belowZero([1, 2, 3])\n false\n >>> belowZero([1, 2, -4, 5])\n true\n */\nconst belowZero = (operations) => {\n", "canonical_solution": " var balance = 0;\n for (const op of operations) {\n balance += op;\n if (balance < 0) {\n return true;\n }\n }\n return false;\n}\n\n", "test": "const testBelowZero = () => {\n console.assert(belowZero([]) === false)\n console.assert(belowZero([1, 2, -3, 1, 2, -3]) === false)\n console.assert(belowZero([1, 2, -4, 5, 6]) === true)\n console.assert(belowZero([1, -1, 2, -2, 5, -5, 4, -4]) === false)\n console.assert(belowZero([1, -1, 2, -2, 5, -5, 4, -5]) === true)\n console.assert(belowZero([1, -2, 2, -2, 5, -5, 4, -4]) === true)\n}\n\ntestBelowZero()\n", "declaration": "\nconst belowZero = (operations) => {\n", "example_test": "const testBelowZero = () => {\n console.assert(belowZero([1, 2, 3]) === false)\n console.assert(belowZero([1, 2, -4, 5]) === true)\n}\ntestBelowZero()\n", "buggy_solution": " var balance = 0;\n for (const op of operations) {\n balance += op;\n if (balance == 0) {\n return true;\n }\n }\n return false;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "belowZero"} -{"task_id": "JavaScript/4", "prompt": "/* For a given list of input numbers, calculate Mean Absolute Deviation\n around the mean of this dataset.\n Mean Absolute Deviation is the average absolute difference between each\n element and a centerpoint (mean in this case):\n MAD = average | x - x_mean |\n >>> meanAbsoluteDeviation([1.0, 2.0, 3.0, 4.0])\n 1.0\n */\nconst meanAbsoluteDeviation = (numbers) => {\n", "canonical_solution": " var mean = numbers.reduce((prev, item) => {\n return prev + item;\n }, 0) / numbers.length;\n return numbers.reduce((prev, item) => {\n return prev + Math.abs(item - mean);\n }, 0) / numbers.length;\n\n}\n\n", "test": "const testMeanAbsoluteDeviation = () => {\n console.assert(\n Math.abs(meanAbsoluteDeviation([1.0, 2.0, 3.0]) - 2.0 / 3.0) < 1e-6\n )\n console.assert(\n Math.abs(meanAbsoluteDeviation([1.0, 2.0, 3.0, 4.0]) - 1.0) < 1e-6\n )\n console.assert(\n Math.abs(meanAbsoluteDeviation([1.0, 2.0, 3.0, 4.0, 5.0]) - 6.0 / 5.0) < 1e-6\n )\n}\n\ntestMeanAbsoluteDeviation()\n", "declaration": "\nconst meanAbsoluteDeviation = (numbers) => {\n", "example_test": "const testMeanAbsoluteDeviation = () => {\n console.assert(\n Math.abs(meanAbsoluteDeviation([1.0, 2.0, 3.0, 4.0]) - 1.0) < 1e-6\n )\n}\ntestMeanAbsoluteDeviation()\n", "buggy_solution": " var mean = numbers.reduce((prev, item) => {\n return prev + item;\n }, 0) / numbers.length;\n return numbers.reduce((prev, item) => {\n return prev + Math.abs(item - mean);\n }, 0) / mean;\n\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "meanAbsoluteDeviation"} -{"task_id": "JavaScript/5", "prompt": "/* Insert a number 'delimeter' between every two consecutive elements of input list `numbers'\n >>> intersperse([], 4)\n []\n >>> intersperse([1, 2, 3], 4)\n [1, 4, 2, 4, 3]\n */\nconst intersperse = (numbers, delimeter) => {\n", "canonical_solution": " if (!Array.isArray(numbers) || numbers.length == 0)\n return [];\n var result = [];\n for (const n of numbers) {\n result.push(n, delimeter);\n }\n result.pop();\n return result;\n}\n\n", "test": "const testIntersperse = () => {\n console.assert(JSON.stringify(intersperse([], 7)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(\n intersperse([5, 6, 3, 2], 8)) === JSON.stringify([5, 8, 6, 8, 3, 8, 2])\n )\n console.assert(\n JSON.stringify(\n intersperse([2, 2, 2], 2)) === JSON.stringify([2, 2, 2, 2, 2])\n )\n}\n\ntestIntersperse()\n", "declaration": "\nconst intersperse = (numbers, delimeter) => {\n", "example_test": "const testIntersperse = () => {\n console.assert(JSON.stringify(intersperse([], 4)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(\n intersperse([1,2,3], 4)) === JSON.stringify([1,4,2,4,3])\n )\n}\ntestIntersperse()\n", "buggy_solution": " if (!Array.isArray(numbers) || numbers.length == 0)\n return [];\n var result = [];\n for (const n of numbers) {\n result.push(n, delimeter);\n }\n return result;\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "intersperse"} -{"task_id": "JavaScript/6", "prompt": "/* Input to this function is a string represented multiple groups for nested parentheses separated by spaces.\n For each of the group, output the deepest level of nesting of parentheses.\n E.g. (()()) has maximum two levels of nesting while ((())) has three.\n\n >>> parseNestedParens('(()()) ((())) () ((())()())')\n [2, 3, 1, 3]\n */\nconst parseNestedParens = (paren_string) => {\n", "canonical_solution": " var parseParenGroup = function (s) {\n let depth = 0, max_depth = 0;\n for (const c of s) {\n if (c == '(') {\n depth += 1;\n max_depth = Math.max(max_depth, depth);\n } else {\n depth -= 1;\n }\n }\n return max_depth;\n }\n return paren_string.split(' ')\n .filter(x => x != '')\n .map(x => parseParenGroup(x));\n}\n\n", "test": "const testParseNestedParens = () => {\n console.assert(\n JSON.stringify(parseNestedParens('(()()) ((())) () ((())()())')) ===\n JSON.stringify([2, 3, 1, 3])\n )\n console.assert(\n JSON.stringify(parseNestedParens('() (()) ((())) (((())))')) ===\n JSON.stringify([1, 2, 3, 4])\n )\n console.assert(\n JSON.stringify(parseNestedParens('(()(())((())))')) === JSON.stringify([4])\n )\n}\n\ntestParseNestedParens()\n", "declaration": "\nconst parseNestedParens = (paren_string) => {\n", "example_test": "const testParseNestedParens = () => {\n console.assert(\n JSON.stringify(parseNestedParens('(()()) ((())) () ((())()())')) ===\n JSON.stringify([2, 3, 1, 3])\n )\n}\ntestParseNestedParens()\n", "buggy_solution": " var parseParenGroup = function (s) {\n let depth = 0, max_depth = 0;\n for (const c of s) {\n if (c == '(') {\n depth += 1;\n max_depth = Math.max(max_depth, depth);\n } else {\n max_depth -= 1;\n }\n }\n return max_depth;\n }\n return paren_string.split(' ')\n .filter(x => x != '')\n .map(x => parseParenGroup(x));\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "parseNestedParens"} -{"task_id": "JavaScript/7", "prompt": "/* Filter an input list of strings only for ones that contain given substring\n >>> filterBySubstring([], 'a')\n []\n >>> filterBySubstring(['abc', 'bacd', 'cde', 'array'], 'a')\n ['abc', 'bacd', 'array']\n */\nconst filterBySubstring = (strings, substring) => {\n", "canonical_solution": " return strings.filter(x => x.indexOf(substring) != -1);\n}\n\n", "test": "const testFilterBySubstring = () => {\n console.assert(\n JSON.stringify(filterBySubstring([], 'john')) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(\n filterBySubstring(\n ['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'],\n 'xxx'\n )\n ) === JSON.stringify(['xxx', 'xxxAAA', 'xxx'])\n )\n console.assert(\n JSON.stringify(\n filterBySubstring(\n ['xxx', 'asd', 'aaaxxy', 'john doe', 'xxxAAA', 'xxx'],\n 'xx'\n )\n ) === JSON.stringify(['xxx', 'aaaxxy', 'xxxAAA', 'xxx'])\n )\n console.assert(\n JSON.stringify(\n filterBySubstring(['grunt', 'trumpet', 'prune', 'gruesome'], 'run')\n ) === JSON.stringify(['grunt', 'prune'])\n )\n}\n\ntestFilterBySubstring()\n", "declaration": "\nconst filterBySubstring = (strings, substring) => {\n", "example_test": "const testFilterBySubstring = () => {\n console.assert(\n JSON.stringify(filterBySubstring([], 'a')) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(\n filterBySubstring(\n ['abc', 'bacd', 'cde', 'array'], 'a'\n )\n ) === JSON.stringify(['abc', 'bacd', 'array'])\n )\n}\ntestFilterBySubstring()\n", "buggy_solution": " return strings.filter(x => substring.indexOf(x) != -1);\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "filterBySubstring"} -{"task_id": "JavaScript/8", "prompt": "/* For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.\n Empty sum should be equal to 0 and empty product should be equal to 1.\n >>> sumProduct([])\n (0, 1)\n >>> sumProduct([1, 2, 3, 4])\n (10, 24)\n */\nconst sumProduct = (numbers, int) => {\n", "canonical_solution": " var sum_value = 0, prod_value = 1;\n for (const n of numbers) {\n sum_value += n;\n prod_value *= n;\n }\n return [sum_value, prod_value];\n}\n\n", "test": "const testSumProduct = () => {\n console.assert(JSON.stringify(sumProduct([])) === JSON.stringify([0, 1]))\n console.assert(\n JSON.stringify(sumProduct([1, 1, 1])) === JSON.stringify([3, 1])\n )\n console.assert(\n JSON.stringify(sumProduct([100, 0])) === JSON.stringify([100, 0])\n )\n console.assert(\n JSON.stringify(\n sumProduct([3, 5, 7])) === JSON.stringify([3 + 5 + 7, 3 * 5 * 7])\n )\n console.assert(JSON.stringify(sumProduct([10])) === JSON.stringify([10, 10]))\n}\n\ntestSumProduct()\n", "declaration": "\nconst sumProduct = (numbers, int) => {\n", "example_test": "const testSumProduct = () => {\n console.assert(JSON.stringify(sumProduct([])) === JSON.stringify([0, 1]))\n console.assert(\n JSON.stringify(sumProduct([1, 2,3,4])) === JSON.stringify([10, 24])\n )\n}\ntestSumProduct()\n", "buggy_solution": " var sum_value = 0, prod_value = 0;\n for (const n of numbers) {\n sum_value += n;\n prod_value *= n;\n }\n return [sum_value, prod_value];\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "sumProduct"} -{"task_id": "JavaScript/9", "prompt": "/* From a given list of integers, generate a list of rolling maximum element found until given moment\n in the sequence.\n >>> rollingMax([1, 2, 3, 2, 3, 4, 2])\n [1, 2, 3, 3, 3, 4, 4]\n */\nconst rollingMax = (numbers) => {\n", "canonical_solution": " var running_max, result = [];\n for (const n of numbers) {\n if (running_max == undefined)\n running_max = n;\n else\n running_max = Math.max(running_max, n);\n result.push(running_max);\n }\n return result;\n}\n\n", "test": "const testRollingMax = () => {\n console.assert(JSON.stringify(rollingMax([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(rollingMax([1, 2, 3, 4])) === JSON.stringify([1, 2, 3, 4])\n )\n console.assert(\n JSON.stringify(rollingMax([4, 3, 2, 1])) === JSON.stringify([4, 4, 4, 4])\n )\n console.assert(\n JSON.stringify(\n rollingMax([3, 2, 3, 100, 3])) === JSON.stringify([3, 3, 3, 100, 100])\n )\n}\n\ntestRollingMax()\n", "declaration": "\nconst rollingMax = (numbers) => {\n", "example_test": "const testRollingMax = () => {\n console.assert(JSON.stringify(rollingMax([1, 2, 3, 2, 3, 4, 2])) === JSON.stringify([1, 2, 3, 3, 3, 4, 4]))\n}\ntestRollingMax()\n", "buggy_solution": " var running_max, result = [];\n for (const n of numbers) {\n if (running_max == undefined)\n running_max = n;\n else\n running_max = Math.max(numbers);\n result.push(running_max);\n }\n return result;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "rollingMax"} -{"task_id": "JavaScript/10", "prompt": "/* Test if gniven strig is a palindrome */\nconst isPalindrome = (string) => {\n return string == string.split('').reverse().join('');\n}\n\n/* Find the shortest palindrome that begins with a supplied string.\n Algorithm idea is simple:\n - Find the longest postfix of supplied string that is a palindrome.\n - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.\n >>> makePalindrome('')\n ''\n >>> makePalindrome('cat')\n 'catac'\n >>> makePalindrome('cata')\n 'catac'\n */\nconst makePalindrome = (string) => {\n", "canonical_solution": " if (string == '')\n return '';\n var beginning_of_suffix = 0;\n while (!isPalindrome(string.slice(beginning_of_suffix)))\n beginning_of_suffix += 1;\n return string + string.slice(0, beginning_of_suffix).split('').reverse().join('');\n}\n\n", "test": "const testmakePalindrome = () => {\n console.assert(makePalindrome('') === '')\n console.assert(makePalindrome('x') === 'x')\n console.assert(makePalindrome('xyz') === 'xyzyx')\n console.assert(makePalindrome('xyx') === 'xyx')\n console.assert(makePalindrome('jerry') === 'jerryrrej')\n}\n\ntestmakePalindrome()\n", "declaration": "const isPalindrome = (string) => {\n return string == string.split('').reverse().join('');\n}\n\nconst makePalindrome = (string) => {\n", "example_test": "const testmakePalindrome = () => {\n console.assert(makePalindrome('') === '')\n console.assert(makePalindrome('cat') === 'catac')\n console.assert(makePalindrome('cata') === 'catac')\n}\ntestmakePalindrome()\n", "buggy_solution": " if (string == '')\n return '';\n var beginning_of_suffix = 0;\n while (!isPalindrome(string))\n beginning_of_suffix += 1;\n return string + string.slice(0, beginning_of_suffix).split('').reverse().join('');\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "stackoverflow", "entry_point": "makePalindrome"} -{"task_id": "JavaScript/11", "prompt": "/* Input are two strings a and b consisting only of 1s and 0s.\n Perform binary XOR on these inputs and return result also as a string.\n >>> stringXor('010', '110')\n '100'\n */\nconst stringXor = (a, b) => {\n", "canonical_solution": " var xor = function (i, j) {\n if (i == j)\n return '0';\n else\n return '1';\n }\n return a.split('').map((item, index) => xor(item, b[index])).join('');\n}\n\n", "test": "const testStringXor = () => {\n console.assert(stringXor('111000', '101010') === '010010')\n console.assert(stringXor('1', '1') === '0')\n console.assert(stringXor('0101', '0000') === '0101')\n}\n\ntestStringXor()\n", "declaration": "\nconst stringXor = (a, b) => {\n", "example_test": "const testStringXor = () => {\n console.assert(stringXor('010', '110') === '100')\n}\ntestStringXor()\n", "buggy_solution": " var xor = function (i, j) {\n if (i == j)\n return '1';\n else\n return '0';\n }\n return a.split('').map((item, index) => xor(item, b[index])).join('');\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "stringXor"} -{"task_id": "JavaScript/12", "prompt": "/* Out of list of strings, return the longest one. Return the first one in case of multiple\n strings of the same length. Return null in case the input list is empty.\n >>> longest([])\n\n >>> longest(['a', 'b', 'c'])\n 'a'\n >>> longest(['a', 'bb', 'ccc'])\n 'ccc'\n */\nconst longest = (strings) => {\n", "canonical_solution": " if (!Array.isArray(strings) || strings.length == 0)\n return null;\n var maxlen = Math.max(...strings.map(x => x.length));\n for (const s of strings) {\n if (s.length == maxlen) {\n return s;\n }\n }\n}\n\n", "test": "const testLongest = () => {\n console.assert(longest([]) === null)\n console.assert(longest(['x', 'y', 'z']) === 'x')\n console.assert(longest(['x', 'yyy', 'zzzz', 'www', 'kkkk', 'abc']) === 'zzzz')\n}\n\ntestLongest()\n", "declaration": "\nconst longest = (strings) => {\n", "example_test": "const testLongest = () => {\n console.assert(longest([]) === null)\n console.assert(longest(['a', 'b', 'c']) === 'a')\n console.assert(longest(['a', 'bb', 'ccc']) === 'ccc')\n}\ntestLongest()\n", "buggy_solution": " if (!Array.isArray(strings) || strings.length == 0)\n return null;\n var maxlen = Math.max(...strings.map(x => x.length));\n for (const s of strings) {\n if (s.length > maxlen) {\n return s;\n }\n }\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "longest"} -{"task_id": "JavaScript/13", "prompt": "/* Return a greatest common divisor of two integers a and b\n >>> greatestCommonDivisor(3, 5)\n 1\n >>> greatestCommonDivisor(25, 15)\n 5\n */\nconst greatestCommonDivisor = (a, b) => {\n", "canonical_solution": " while (b != 0) {\n let temp = a;\n a = b;\n b = temp % b;\n }\n return a;\n}\n\n", "test": "const testGreatestCommonDivisor = () => {\n console.assert(greatestCommonDivisor(3, 7) === 1)\n console.assert(greatestCommonDivisor(10, 15) === 5)\n console.assert(greatestCommonDivisor(49, 14) === 7)\n console.assert(greatestCommonDivisor(144, 60) === 12)\n}\n\ntestGreatestCommonDivisor()\n", "declaration": "\nconst greatestCommonDivisor = (a, b) => {\n", "example_test": "const testGreatestCommonDivisor = () => {\n console.assert(greatestCommonDivisor(3, 5) === 1)\n console.assert(greatestCommonDivisor(25, 15) === 5)\n}\ntestGreatestCommonDivisor()\n", "buggy_solution": " while (b != 0) {\n let temp = a;\n a = b;\n b = temp % b;\n }\n return b;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "greatestCommonDivisor"} -{"task_id": "JavaScript/14", "prompt": "/* Return list of all prefixes from shortest to longest of the input string\n >>> allPrefixes('abc')\n ['a', 'ab', 'abc']\n */\nconst allPrefixes = (string) => {\n", "canonical_solution": " var result = [];\n for (let i = 0; i < string.length; i++) {\n result.push(string.slice(0, i+1));\n }\n return result;\n}\n\n", "test": "const testAllPrefixes = () => {\n console.assert(JSON.stringify(allPrefixes('')) === JSON.stringify([]))\n console.assert(\n JSON.stringify(\n allPrefixes('asdfgh')) ===\n JSON.stringify(['a', 'as', 'asd', 'asdf', 'asdfg', 'asdfgh'])\n )\n console.assert(\n JSON.stringify(allPrefixes('WWW')) === JSON.stringify(['W', 'WW', 'WWW'])\n )\n}\n\ntestAllPrefixes()\n", "declaration": "\nconst allPrefixes = (string) => {\n", "example_test": "const testAllPrefixes = () => {\n console.assert(\n JSON.stringify(\n allPrefixes('abc')) ===\n JSON.stringify(['a', 'ab', 'abc'])\n )\n}\ntestAllPrefixes()\n", "buggy_solution": " var result = [];\n for (let i = 0; i < string.length-1; i++) {\n result.push(string.slice(0, i+1));\n }\n return result;\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "allPrefixes"} -{"task_id": "JavaScript/15", "prompt": "/* Return a string containing space-delimited numbers starting from 0 upto n inclusive.\n >>> stringSequence(0)\n '0'\n >>> stringSequence(5)\n '0 1 2 3 4 5'\n */\nconst stringSequence = (n) => {\n", "canonical_solution": " return [...Array(n).keys(), n].join(' ')\n}\n\n", "test": "const testStringSequence = () => {\n console.assert(stringSequence(0) === '0')\n console.assert(stringSequence(3) === '0 1 2 3')\n console.assert(stringSequence(10) === '0 1 2 3 4 5 6 7 8 9 10')\n}\n\ntestStringSequence()\n", "declaration": "\nconst stringSequence = (n) => {\n", "example_test": "const testStringSequence = () => {\n console.assert(stringSequence(0) === '0')\n console.assert(stringSequence(5) === '0 1 2 3 4 5')\n}\ntestStringSequence()\n", "buggy_solution": " return [...Array(n-1).keys(), n].join(' ')\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "stringSequence"} -{"task_id": "JavaScript/16", "prompt": "/* Given a string, find out how many distinct characters (regardless of case) does it consist of\n >>> countDistinctCharacters('xyzXYZ')\n 3\n >>> countDistinctCharacters('Jerry')\n 4\n */\nconst countDistinctCharacters = (string) => {\n", "canonical_solution": " return (new Set(string.toLowerCase())).size;\n\n}\n\n", "test": "const testCountDistinctCharacters = () => {\n console.assert(countDistinctCharacters('') === 0)\n console.assert(countDistinctCharacters('abcde') === 5)\n console.assert(countDistinctCharacters('abcde' + 'cade' + 'CADE') === 5)\n console.assert(countDistinctCharacters('aaaaAAAAaaaa') === 1)\n console.assert(countDistinctCharacters('Jerry jERRY JeRRRY') === 5)\n}\n\ntestCountDistinctCharacters()\n", "declaration": "\nconst countDistinctCharacters = (string) => {\n", "example_test": "const testCountDistinctCharacters = () => {\n console.assert(countDistinctCharacters('xyzXYZ') === 3)\n console.assert(countDistinctCharacters('Jerry') === 4)\n}\ntestCountDistinctCharacters()\n", "buggy_solution": " return (new Set(string)).size;\n\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "countDistinctCharacters"} -{"task_id": "JavaScript/17", "prompt": "/* Input to this function is a string representing musical notes in a special ASCII format.\n Your task is to parse this string and return list of integers corresponding to how many beats does each\n not last.\n\n Here is a legend:\n 'o' - whole note, lasts four beats\n 'o|' - half note, lasts two beats\n '.|' - quater note, lasts one beat\n\n >>> parseMusic('o o| .| o| o| .| .| .| .| o o')\n [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]\n */\nconst parseMusic = (music_string) => {\n", "canonical_solution": " const note_map = {'o': 4, 'o|': 2, '.|': 1};\n return music_string.split(' ').filter(x => x != '').map(x => note_map[x]);\n}\n\n", "test": "const testParseMusic = () => {\n console.assert(JSON.stringify(parseMusic('')) === JSON.stringify([]))\n console.assert(\n JSON.stringify(parseMusic('o o o o')) === JSON.stringify([4, 4, 4, 4])\n )\n console.assert(\n JSON.stringify(parseMusic('.| .| .| .|')) === JSON.stringify([1, 1, 1, 1])\n )\n console.assert(\n JSON.stringify(parseMusic('o| o| .| .| o o o o')) ===\n JSON.stringify([2, 2, 1, 1, 4, 4, 4, 4])\n )\n console.assert(\n JSON.stringify(parseMusic('o| .| o| .| o o| o o|')) ===\n JSON.stringify([2, 1, 2, 1, 4, 2, 4, 2])\n )\n}\n\ntestParseMusic()\n", "declaration": "\nconst parseMusic = (music_string) => {\n", "example_test": "const testParseMusic = () => {\n console.assert(JSON.stringify(parseMusic('o o| .| o| o| .| .| .| .| o o')) === JSON.stringify([4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]))\n}\ntestParseMusic()\n", "buggy_solution": " const note_map = {'o': 3, 'o|': 2, '.|': 1};\n return music_string.split(' ').filter(x => x != '').map(x => note_map[x]);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "parseMusic"} -{"task_id": "JavaScript/18", "prompt": "/* Find how many times a given substring can be found in the original string. Count overlaping cases.\n >>> howManyTimes('', 'a')\n 0\n >>> howManyTimes('aaa', 'a')\n 3\n >>> howManyTimes('aaaa', 'aa')\n 3\n */\nconst howManyTimes = (string, substring) => {\n", "canonical_solution": " var times = 0;\n for (let i = 0; i < string.length - substring.length + 1; i++) {\n if (string.slice(i, i+substring.length) == substring) {\n times += 1;\n }\n }\n return times;\n}\n\n", "test": "const testHowManyTimes = () => {\n console.assert(howManyTimes('', 'x') === 0)\n console.assert(howManyTimes('xyxyxyx', 'x') === 4)\n console.assert(howManyTimes('cacacacac', 'cac') === 4)\n console.assert(howManyTimes('john doe', 'john') === 1)\n}\n\ntestHowManyTimes()\n", "declaration": "\nconst howManyTimes = (string, substring) => {\n", "example_test": "const testHowManyTimes = () => {\n console.assert(howManyTimes('', 'a') === 0)\n console.assert(howManyTimes('aaa', 'a') === 3)\n console.assert(howManyTimes('aaaa', 'aa') === 3)\n}\ntestHowManyTimes()\n", "buggy_solution": " var times = 0;\n for (let i = 0; i < string.length - substring.length; i++) {\n if (string.slice(i, i+substring.length) == substring) {\n times += 1;\n }\n }\n return times;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "howManyTimes"} -{"task_id": "JavaScript/19", "prompt": "/* Input is a space-delimited string of numberals from 'zero' to 'nine'.\n Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.\n Return the string with numbers sorted from smallest to largest\n >>> sortNumbers('three one five')\n 'one three five'\n */\nconst sortNumbers = (numbers) => {\n", "canonical_solution": " const value_map = {\n 'zero': 0,\n 'one': 1,\n 'two': 2,\n 'three': 3,\n 'four': 4,\n 'five': 5,\n 'six': 6,\n 'seven': 7,\n 'eight': 8,\n 'nine': 9\n };\n return numbers.split(' ')\n .filter(x => x != '')\n .sort((a, b) => value_map[a] - value_map[b])\n .join(' ');\n}\n\n", "test": "const testSortNumbers = () => {\n console.assert(sortNumbers('') === '')\n console.assert(sortNumbers('three') === 'three')\n console.assert(sortNumbers('three five nine') === 'three five nine')\n console.assert(\n sortNumbers(\n 'five zero four seven nine eight') === 'zero four five seven eight nine'\n )\n console.assert(\n sortNumbers(\n 'six five four three two one zero') === 'zero one two three four five six'\n )\n}\n\ntestSortNumbers()\n", "declaration": "\nconst sortNumbers = (numbers) => {\n", "example_test": "const testSortNumbers = () => {\n console.assert(sortNumbers('three one five') === 'one three five')\n}\ntestSortNumbers()\n", "buggy_solution": " const value_map = {\n 'zero': 0,\n 'one': 1,\n 'two': 2,\n 'three': 3,\n 'four': 4,\n 'five': 5,\n 'six': 6,\n 'seven': 7,\n 'eight': 8,\n 'nine': 9\n };\n return numbers.split(' ')\n .filter(x => x != '')\n .join(' ');\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sortNumbers"} -{"task_id": "JavaScript/20", "prompt": "/* From a supplied list of numbers (of length at least two) select and return two that are the closest to each\n other and return them in order (smaller number, larger number).\n >>> findClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2])\n (2.0, 2.2)\n >>> findClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0])\n (2.0, 2.0)\n */\nconst findClosestElements = (numbers) => {\n", "canonical_solution": " var closest_pair, distance;\n for (let i = 0; i < numbers.length; i++)\n for (let j = 0; j < numbers.length; j++)\n if (i != j) {\n let a = numbers[i], b = numbers[j];\n if (distance == null) {\n distance = Math.abs(a - b);\n closest_pair = [Math.min(a, b), Math.max(a, b)];\n } else {\n let new_distance = Math.abs(a - b);\n if (new_distance < distance) {\n distance = new_distance;\n closest_pair = [Math.min(a, b), Math.max(a, b)];\n }\n }\n }\n return closest_pair;\n}\n\n", "test": "const testFindClosestElements = () => {\n console.assert(\n JSON.stringify(findClosestElements([1.0, 2.0, 3.9, 4.0, 5.0, 2.2])) ===\n JSON.stringify([3.9, 4.0])\n )\n console.assert(\n JSON.stringify(findClosestElements([1.0, 2.0, 5.9, 4.0, 5.0])) ===\n JSON.stringify([5.0, 5.9])\n )\n console.assert(\n JSON.stringify(findClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2])) ===\n JSON.stringify([2.0, 2.2])\n )\n console.assert(\n JSON.stringify(findClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0])) ===\n JSON.stringify([2.0, 2.0])\n )\n console.assert(\n JSON.stringify(findClosestElements([1.1, 2.2, 3.1, 4.1, 5.1])) ===\n JSON.stringify([2.2, 3.1])\n )\n}\n\ntestFindClosestElements()\n", "declaration": "\nconst findClosestElements = (numbers) => {\n", "example_test": "const testFindClosestElements = () => {\n console.assert(\n JSON.stringify(findClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2])) ===\n JSON.stringify([2.0, 2.2])\n )\n console.assert(\n JSON.stringify(findClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0])) ===\n JSON.stringify([2.0, 2.0])\n )\n}\ntestFindClosestElements()\n", "buggy_solution": " var closest_pair, distance;\n for (let i = 0; i < numbers.length; i++)\n for (let j = 0; j < numbers.length; j++)\n if (i != j) {\n let a = numbers[i], b = numbers[j];\n if (distance == null) {\n distance = Math.abs(a - b);\n closest_pair = [Math.min(a, b), Math.max(a, b)];\n } else {\n let new_distance = Math.abs(a - b);\n if (new_distance > distance) {\n distance = new_distance;\n closest_pair = [Math.min(a, b), Math.max(a, b)];\n }\n }\n }\n return closest_pair;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "findClosestElements"} -{"task_id": "JavaScript/21", "prompt": "/* Given list of numbers (of at least two elements), apply a linear transform to that list,\n such that the smallest number will become 0 and the largest will become 1\n >>> rescaleToUnit([1.0, 2.0, 3.0, 4.0, 5.0])\n [0.0, 0.25, 0.5, 0.75, 1.0]\n */\nconst rescaleToUnit = (numbers) => {\n", "canonical_solution": " var min_number = Math.min(...numbers);\n var max_number = Math.max(...numbers);\n return numbers.map(x => (x - min_number) / (max_number - min_number));\n}\n\n", "test": "const testRescaleToUnit = () => {\n console.assert(\n JSON.stringify(rescaleToUnit([2.0, 49.9])) === JSON.stringify([0.0, 1.0])\n )\n console.assert(\n JSON.stringify(rescaleToUnit([100.0, 49.9])) === JSON.stringify([1.0, 0.0])\n )\n console.assert(\n JSON.stringify(rescaleToUnit([1.0, 2.0, 3.0, 4.0, 5.0])) ===\n JSON.stringify([0.0, 0.25, 0.5, 0.75, 1.0])\n )\n console.assert(\n JSON.stringify(rescaleToUnit([2.0, 1.0, 5.0, 3.0, 4.0])) ===\n JSON.stringify([0.25, 0.0, 1.0, 0.5, 0.75])\n )\n console.assert(\n JSON.stringify(rescaleToUnit([12.0, 11.0, 15.0, 13.0, 14.0])) ===\n JSON.stringify([0.25, 0.0, 1.0, 0.5, 0.75])\n )\n}\n\ntestRescaleToUnit()\n", "declaration": "\nconst rescaleToUnit = (numbers) => {\n", "example_test": "const testRescaleToUnit = () => {\n console.assert(\n JSON.stringify(rescaleToUnit([1.0, 2.0, 3.0, 4.0, 5.0])) ===\n JSON.stringify([0.0, 0.25, 0.5, 0.75, 1.0])\n )\n}\ntestRescaleToUnit()\n", "buggy_solution": " var min_number = Math.min(...numbers);\n var max_number = Math.max(...numbers);\n return numbers.map(x => (x - min_number) / (max_number + min_number));\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "rescaleToUnit"} -{"task_id": "JavaScript/22", "prompt": "/* Filter given list of any python values only for integers\n >>> filterIntegers(['a', 3.14, 5])\n [5]\n >>> filterIntegers([1, 2, 3, 'abc', {}, []])\n [1, 2, 3]\n */\nconst filterIntegers = (values) => {\n", "canonical_solution": " return values.filter(x => Number.isInteger(x));\n}\n\n", "test": "const testFilterIntegers = () => {\n console.assert(JSON.stringify(filterIntegers([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(filterIntegers([4, {}, [], 23.2, 9, 'adasd'])) ===\n JSON.stringify([4, 9])\n )\n console.assert(\n JSON.stringify(filterIntegers([3, 'c', 3, 3, 'a', 'b'])) ===\n JSON.stringify([3, 3, 3])\n )\n}\n\ntestFilterIntegers()\n", "declaration": "\nconst filterIntegers = (values) => {\n", "example_test": "const testFilterIntegers = () => {\n console.assert(JSON.stringify(filterIntegers(['a', 3.14, 5])) === JSON.stringify([5]))\n console.assert(\n JSON.stringify(filterIntegers([1, 2, 3, 'abc', {}, []])) ===\n JSON.stringify([1,2,3])\n )\n}\ntestFilterIntegers()\n", "buggy_solution": " values.filter(x => Number.isInteger(x));\n return values;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "filterIntegers"} -{"task_id": "JavaScript/23", "prompt": "/* Return length of given string\n >>> strlen('')\n 0\n >>> strlen('abc')\n 3\n */\nconst strlen = (string) => {\n", "canonical_solution": " return string.length;\n}\n\n", "test": "const testStrlen = () => {\n console.assert(strlen('') === 0)\n console.assert(strlen('x') === 1)\n console.assert(strlen('asdasnakj') === 9)\n}\n\ntestStrlen()\n", "declaration": "\nconst strlen = (string) => {\n", "example_test": "const testStrlen = () => {\n console.assert(strlen('') === 0)\n console.assert(strlen('abc') === 3)\n}\ntestStrlen()\n", "buggy_solution": " return string.length - 1;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "strlen"} -{"task_id": "JavaScript/24", "prompt": "/* For a given number n, find the largest number that divides n evenly, smaller than n\n >>> largestDivisor(15)\n 5\n */\nconst largestDivisor = (n) => {\n", "canonical_solution": " for (let i = n - 1; i >= 0; i--)\n if (n % i == 0)\n return i;\n}\n\n", "test": "const testLargestDivisor = () => {\n console.assert(largestDivisor(3) === 1)\n console.assert(largestDivisor(7) === 1)\n console.assert(largestDivisor(10) === 5)\n console.assert(largestDivisor(100) === 50)\n console.assert(largestDivisor(49) === 7)\n}\n\ntestLargestDivisor()\n", "declaration": "\nconst largestDivisor = (n) => {\n", "example_test": "const testLargestDivisor = () => {\n console.assert(largestDivisor(15) === 5)\n}\ntestLargestDivisor()\n", "buggy_solution": " for (let i = n - 1; i >= 0; i--)\n if (n - i == 0)\n return i;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "largestDivisor"} -{"task_id": "JavaScript/25", "prompt": "/* Return list of prime factors of given integer in the order from smallest to largest.\n Each of the factors should be listed number of times corresponding to how many times it appeares in factorization.\n Input number should be equal to the product of all factors\n >>> factorize(8)\n [2, 2, 2]\n >>> factorize(25)\n [5, 5]\n >>> factorize(70)\n [2, 5, 7]\n */\nconst factorize = (n) => {\n", "canonical_solution": " var fact = [], i = 2;\n while (i <= Math.sqrt(n) + 1) {\n if (n % i == 0) {\n fact.push(i);\n n = n / i;\n } else {\n i += 1;\n }\n }\n\n if (n > 1)\n fact.push(n);\n return fact;\n}\n\n", "test": "const testFactorize = () => {\n console.assert(JSON.stringify(factorize(2)) === JSON.stringify([2]))\n console.assert(JSON.stringify(factorize(4)) === JSON.stringify([2, 2]))\n console.assert(JSON.stringify(factorize(8)) === JSON.stringify([2, 2, 2]))\n console.assert(JSON.stringify(factorize(3 * 19)) === JSON.stringify([3, 19]))\n console.assert(\n JSON.stringify(factorize(3 * 19 * 3 * 19)) ===\n JSON.stringify([3, 3, 19, 19])\n )\n console.assert(\n JSON.stringify(factorize(3 * 19 * 3 * 19 * 3 * 19)) ===\n JSON.stringify([3, 3, 3, 19, 19, 19])\n )\n console.assert(\n JSON.stringify(factorize(3 * 19 * 19 * 19)) ===\n JSON.stringify([3, 19, 19, 19])\n )\n console.assert(\n JSON.stringify(factorize(3 * 2 * 3)) === JSON.stringify([2, 3, 3])\n )\n}\n\ntestFactorize()\n", "declaration": "\nconst factorize = (n) => {\n", "example_test": "const testFactorize = () => {\n console.assert(JSON.stringify(factorize(8)) === JSON.stringify([2, 2, 2]))\n console.assert(JSON.stringify(factorize(25)) === JSON.stringify([5,5]))\n console.assert(\n JSON.stringify(factorize(70)) ===\n JSON.stringify([2,5,7])\n )\n}\ntestFactorize()\n", "buggy_solution": " var fact = [], i = 0;\n while (i <= Math.sqrt(n) + 1) {\n if (n % i == 0) {\n fact.push(i);\n n = n / i;\n } else {\n i += 1;\n }\n }\n\n if (n > 1)\n fact.push(n);\n return fact;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "factorize"} -{"task_id": "JavaScript/26", "prompt": "/* From a list of integers, remove all elements that occur more than once.\n Keep order of elements left the same as in the input.\n >>> removeDuplicates([1, 2, 3, 2, 4])\n [1, 3, 4]\n */\nconst removeDuplicates = (numbers) => {\n", "canonical_solution": " var dict = new Object();\n for (const num of numbers) {\n if (num in dict) {\n dict[num] += 1;\n } else {\n dict[num] = 1;\n }\n }\n return numbers.filter(x => dict[x] <= 1);\n}\n\n", "test": "const testRemoveDuplicates = () => {\n console.assert(JSON.stringify(removeDuplicates([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(removeDuplicates([1, 2, 3, 4])) ===\n JSON.stringify([1, 2, 3, 4])\n )\n console.assert(\n JSON.stringify(removeDuplicates([1, 2, 3, 2, 4, 3, 5])) ===\n JSON.stringify([1, 4, 5])\n )\n}\n\ntestRemoveDuplicates()\n", "declaration": "\nconst removeDuplicates = (numbers) => {\n", "example_test": "const testRemoveDuplicates = () => {\n console.assert(\n JSON.stringify(removeDuplicates([1, 2, 3, 2,4])) ===\n JSON.stringify([1,3, 4])\n )\n}\ntestRemoveDuplicates()\n", "buggy_solution": " var dict = new Object();\n for (const num of numbers) {\n if (num in dict) {\n dict[num] += 1;\n } else {\n dict[num] = 1;\n }\n }\n return numbers.filter(x > dict[x] < 1);\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "removeDuplicates"} -{"task_id": "JavaScript/27", "prompt": "/* For a given string, flip lowercase characters to uppercase and uppercase to lowercase.\n >>> flipCase('Hello')\n 'hELLO'\n */\nconst flipCase = (string) => {\n", "canonical_solution": " return string.split('')\n .map(x => (x.toUpperCase() == x ? x.toLowerCase() : x.toUpperCase()))\n .join('');\n}\n\n", "test": "const testFlipCase = () => {\n console.assert(flipCase('') === '')\n console.assert(flipCase('Hello!') === 'hELLO!')\n console.assert(\n flipCase(\n 'These violent delights have violent ends') ===\n 'tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS'\n )\n}\n\ntestFlipCase()\n", "declaration": "\nconst flipCase = (string) => {\n", "example_test": "const testFlipCase = () => {\n console.assert(flipCase('Hello') === 'hELLO')\n}\ntestFlipCase()\n", "buggy_solution": " return string.split('')\n .map(x => (x.toLowerCase() == x ? x.toLowerCase() : x.toUpperCase()))\n .join('');\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "flipCase"} -{"task_id": "JavaScript/28", "prompt": "/* Concatenate list of strings into a single string\n >>> concatenate([])\n ''\n >>> concatenate(['a', 'b', 'c'])\n 'abc'\n */\nconst concatenate = (strings) => {\n", "canonical_solution": " return strings.join('');\n}\n\n", "test": "const testConcatenate = () => {\n console.assert(concatenate([]) === '')\n console.assert(concatenate(['x', 'y', 'z']) === 'xyz')\n console.assert(concatenate(['x', 'y', 'z', 'w', 'k']) === 'xyzwk')\n}\n\ntestConcatenate()\n", "declaration": "\nconst concatenate = (strings) => {\n", "example_test": "const testConcatenate = () => {\n console.assert(concatenate([]) === '')\n console.assert(concatenate(['a', 'b', 'c']) === 'abc')\n}\ntestConcatenate()\n", "buggy_solution": " return strings.join(' ');\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "concatenate"} -{"task_id": "JavaScript/29", "prompt": "/* Filter an input list of strings only for ones that start with a given prefix.\n >>> filterByPrefix([], 'a')\n []\n >>> filterByPrefix(['abc', 'bcd', 'cde', 'array'], 'a')\n ['abc', 'array']\n */\nconst filterByPrefix = (strings, prefix) => {\n", "canonical_solution": " return strings.filter(x => x.startsWith(prefix));\n}\n\n", "test": "const testFilterByPrefix = () => {\n console.assert(\n JSON.stringify(filterByPrefix([], 'john')) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(\n filterByPrefix(['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'], 'xxx')\n ) === JSON.stringify(['xxx', 'xxxAAA', 'xxx'])\n )\n}\n\ntestFilterByPrefix()\n", "declaration": "\nconst filterByPrefix = (strings, prefix) => {\n", "example_test": "const testFilterByPrefix = () => {\n console.assert(\n JSON.stringify(filterByPrefix([], 'a')) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(\n filterByPrefix(['abc', 'bcd', 'cde', 'array'], 'a')\n ) === JSON.stringify(['abc', 'array'])\n )\n}\ntestFilterByPrefix()\n", "buggy_solution": " return strings.filter(x => x.endsWith(prefix));\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "filterByPrefix"} -{"task_id": "JavaScript/30", "prompt": "/*Return only positive numbers in the list.\n >>> getPositive([-1, 2, -4, 5, 6])\n [2, 5, 6]\n >>> getPositive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n [5, 3, 2, 3, 9, 123, 1]\n */\nconst getPositive = (l) => {\n", "canonical_solution": " return l.filter(e => e > 0);\n}\n\n", "test": "const testGetPositive = () => {\n console.assert(\n JSON.stringify(getPositive([-1, -2, 4, 5, 6])) === JSON.stringify([4, 5, 6])\n )\n console.assert(\n JSON.stringify(getPositive([5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10])) ===\n JSON.stringify([5, 3, 2, 3, 3, 9, 123, 1])\n )\n console.assert(JSON.stringify(getPositive([-1, -2])) === JSON.stringify([]))\n console.assert(JSON.stringify(getPositive([])) === JSON.stringify([]))\n}\n\ntestGetPositive()\n", "declaration": "\nconst getPositive = (l) => {\n", "example_test": "const testGetPositive = () => {\n console.assert(\n JSON.stringify(getPositive([-1, 2, -4, 5, 6])) === JSON.stringify([2, 5, 6])\n )\n console.assert(\n JSON.stringify(getPositive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) ===\n JSON.stringify([5, 3, 2, 3, 9, 123, 1])\n )\n}\ntestGetPositive()\n", "buggy_solution": " return l.filter(e => e < 0);\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "getPositive"} -{"task_id": "JavaScript/31", "prompt": "/*Return true if a given number is prime, and false otherwise.\n >>> isPrime(6)\n false\n >>> isPrime(101)\n true\n >>> isPrime(11)\n true\n >>> isPrime(13441)\n true\n >>> isPrime(61)\n true\n >>> isPrime(4)\n false\n >>> isPrime(1)\n false\n */\nconst isPrime = (n) => {\n", "canonical_solution": " if (n < 2)\n return false;\n for (let k = 2; k < n - 1; k++)\n if (n % k == 0)\n return false;\n return true;\n}\n\n", "test": "const testIsPrime = () => {\n console.assert(isPrime(6) === false)\n console.assert(isPrime(101) === true)\n console.assert(isPrime(11) === true)\n console.assert(isPrime(13441) === true)\n console.assert(isPrime(61) === true)\n console.assert(isPrime(4) === false)\n console.assert(isPrime(1) === false)\n console.assert(isPrime(5) === true)\n console.assert(isPrime(11) === true)\n console.assert(isPrime(17) === true)\n console.assert(isPrime(5 * 17) === false)\n console.assert(isPrime(11 * 7) === false)\n console.assert(isPrime(13441 * 19) === false)\n}\n\ntestIsPrime()\n", "declaration": "\nconst isPrime = (n) => {\n", "example_test": "const testIsPrime = () => {\n console.assert(isPrime(6) === false)\n console.assert(isPrime(101) === true)\n console.assert(isPrime(11) === true)\n console.assert(isPrime(13441) === true)\n console.assert(isPrime(61) === true)\n console.assert(isPrime(4) === false)\n console.assert(isPrime(1) === false)\n}\ntestIsPrime()\n", "buggy_solution": " if (n < 1)\n return false;\n for (let k = 1; k < n - 1; k++)\n if (n % k == 0)\n return false;\n return true;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "isPrime"} -{"task_id": "JavaScript/32", "prompt": "/*\n Evaluates polynomial with coefficients xs at point x.\n return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n\n */\nconst poly = (xs, x) => {\n return xs.reduce((prev, item, index) => {\n return prev + item * Math.pow(x, index);\n }, 0);\n}\n\n/*\n xs are coefficients of a polynomial.\n findZero find x such that poly(x) = 0.\n findZero returns only only zero point, even if there are many.\n Moreover, findZero only takes list xs having even number of coefficients\n and largest non zero coefficient as it guarantees\n a solution.\n >>> round(findZero([1, 2]), 2) # f(x) = 1 + 2x\n -0.5\n >>> round(findZero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3\n 1.0\n */\nconst findZero = (xs) => {\n", "canonical_solution": " var begin = -1.0, end = 1.0;\n while (poly(xs, begin) * poly(xs, end) > 0) {\n begin *= 2.0;\n end *= 2.0;\n }\n while (end - begin > 1e-10) {\n let center = (begin + end) / 2.0;\n if (poly(xs, center) * poly(xs, begin) > 0)\n begin = center;\n else\n end = center;\n }\n return begin;\n}\n\n", "test": "const testfindZero = () => {\n const getRandomIntInclusive = (min = 0, max = 9) => {\n min = Math.ceil(min)\n max = Math.floor(max)\n return Math.floor(Math.random() * (max - min + 1)) + min\n }\n\n for (let i = 0; i < 100; i++) {\n let ncoeff = 2 * getRandomIntInclusive(1, 4);\n let coeffs = [];\n for (let j = 0; j < ncoeff; j++) {\n let coeff = getRandomIntInclusive(-10, 10);\n if (coeff === 0)\n coeff = 1;\n coeffs.push(coeff);\n }\n let solution = findZero(coeffs);\n console.assert(Math.abs(poly(coeffs, solution)) < 1e-4);\n }\n}\ntestfindZero()\n", "declaration": "\nconst poly = (xs, x) => {\n return xs.reduce((prev, item, index) => {\n return prev + item * Math.pow(x, index);\n }, 0);\n}\n\nconst findZero = (xs) => {\n", "example_test": "const testPoly = () => {\n console.assert(Math.abs(findZero([1,2])+0.5 < 1e-4));\n console.assert(Math.abs(findZero([-6,11,-6,1])-1 < 1e-4));\n}\ntestPoly()\n", "buggy_solution": " var begin = -1.0, end = 1.0;\n while (poly(xs, begin) * poly(xs, end) > 0) {\n begin *= 2.0;\n end *= 2.0;\n }\n while (begin - end > 1e-10) {\n let center = (begin + end) / 2.0;\n if (poly(xs, center) * poly(xs, end) > 0)\n begin = center;\n else\n end = center;\n }\n return end;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "findZero"} -{"task_id": "JavaScript/33", "prompt": "/*This function takes a list l and returns a list l' such that\n l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal\n to the values of the corresponding indicies of l, but sorted.\n >>> sortThird([1, 2, 3])\n [1, 2, 3]\n >>> sortThird([5, 6, 3, 4, 8, 9, 2])\n [2, 6, 3, 4, 8, 9, 5]\n */\nconst sortThird = (l) => {\n", "canonical_solution": " var three = l.filter((item, index) => index % 3 == 0);\n three.sort((a, b) => (a - b));\n return l.map((item, index) => (index % 3 == 0 ? three[index / 3] : item));\n}\n\n", "test": "const testSortThird = () => {\n console.assert(\n JSON.stringify(sortThird([1, 2, 3])) == JSON.stringify([1, 2, 3])\n )\n console.assert(\n JSON.stringify(sortThird([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) ==\n JSON.stringify([1, 3, -5, 2, -3, 3, 5, 0, 123, 9, -10])\n )\n console.assert(\n JSON.stringify(sortThird([5, 8, -12, 4, 23, 2, 3, 11, 12, -10])) ==\n JSON.stringify([-10, 8, -12, 3, 23, 2, 4, 11, 12, 5])\n )\n console.assert(\n JSON.stringify(sortThird([5, 6, 3, 4, 8, 9, 2])) ==\n JSON.stringify([2, 6, 3, 4, 8, 9, 5])\n )\n console.assert(\n JSON.stringify(sortThird([5, 8, 3, 4, 6, 9, 2])) ==\n JSON.stringify([2, 8, 3, 4, 6, 9, 5])\n )\n console.assert(\n JSON.stringify(sortThird([5, 6, 9, 4, 8, 3, 2])) ==\n JSON.stringify([2, 6, 9, 4, 8, 3, 5])\n )\n console.assert(\n JSON.stringify(sortThird([5, 6, 3, 4, 8, 9, 2, 1])) ==\n JSON.stringify([2, 6, 3, 4, 8, 9, 5, 1])\n )\n}\n\ntestSortThird()\n", "declaration": "\nconst sortThird = (l) => {\n", "example_test": "const testSortThird = () => {\n console.assert(\n JSON.stringify(sortThird([1, 2, 3])) == JSON.stringify([1, 2, 3])\n )\n console.assert(\n JSON.stringify(sortThird([5, 6, 3, 4, 8, 9, 2])) ==\n JSON.stringify([2, 6, 3, 4, 8, 9, 5])\n )\n}\ntestSortThird()\n", "buggy_solution": " var three = l.filter((item, index) => index % 3 == 0);\n return l.map((item, index) => (index % 2 == 0 ? three[index / 3] : item));\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sortThird"} -{"task_id": "JavaScript/34", "prompt": "/*Return sorted unique elements in a list\n >>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123])\n [0, 2, 3, 5, 9, 123]\n */\nconst unique = (l) => {\n", "canonical_solution": " return Array.from(new Set(l)).sort((a, b) => (a - b));\n}\n\n", "test": "const testUnique = () => {\n console.assert(\n JSON.stringify(unique([5, 3, 5, 2, 3, 3, 9, 0, 123])) ===\n JSON.stringify([0, 2, 3, 5, 9, 123])\n )\n}\n\ntestUnique()\n", "declaration": "\nconst unique = (l) => {\n", "example_test": "const testUnique = () => {\n console.assert(\n JSON.stringify(unique([5, 3, 5, 2, 3, 3, 9, 0, 123])) ===\n JSON.stringify([0, 2, 3, 5, 9, 123])\n )\n}\ntestUnique()\n", "buggy_solution": " return l.sort((a, b) => (a - b));\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "unique"} -{"task_id": "JavaScript/35", "prompt": "/*Return maximum element in the list.\n >>> maxElement([1, 2, 3])\n 3\n >>> maxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n 123\n */\nconst maxElement = (l) => {\n", "canonical_solution": " return Math.max(...l);\n}\n\n", "test": "const testMaxElement = () => {\n console.assert(maxElement([1, 2, 3]) === 3)\n console.assert(maxElement([5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10]) === 124)\n}\n\ntestMaxElement()\n", "declaration": "\nconst maxElement = (l) => {\n", "example_test": "const testMaxElement = () => {\n console.assert(maxElement([1, 2, 3]) === 3)\n console.assert(maxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) === 123)\n}\ntestMaxElement()\n", "buggy_solution": " return Math.min(...l);\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "maxElement"} -{"task_id": "JavaScript/36", "prompt": "/*Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.\n >>> fizzBuzz(50)\n 0\n >>> fizzBuzz(78)\n 2\n >>> fizzBuzz(79)\n 3\n */\nconst fizzBuzz = (n) => {\n", "canonical_solution": " var ns = [], ans = 0;\n for (let i = 0; i < n; i++)\n if (i % 11 == 0 || i % 13 == 0)\n ns.push(i);\n var s = ns.map(x => x.toString()).join('');\n for (const c of s)\n ans += (c == '7');\n return ans;\n}\n\n", "test": "const testFizzBuzz = () => {\n console.assert(fizzBuzz(50) === 0)\n console.assert(fizzBuzz(78) === 2)\n console.assert(fizzBuzz(79) === 3)\n console.assert(fizzBuzz(100) === 3)\n console.assert(fizzBuzz(200) === 6)\n console.assert(fizzBuzz(4000) === 192)\n console.assert(fizzBuzz(10000) === 639)\n console.assert(fizzBuzz(100000) === 8026)\n}\n\ntestFizzBuzz()\n", "declaration": "\nconst fizzBuzz = (n) => {\n", "example_test": "const testFizzBuzz = () => {\n console.assert(fizzBuzz(50) === 0)\n console.assert(fizzBuzz(78) === 2)\n console.assert(fizzBuzz(79) === 3)\n}\ntestFizzBuzz()\n", "buggy_solution": " var ns = [], ans = 0;\n for (let i = 0; i < n; i++)\n if (i % 11 == 0 && i % 13 == 0)\n ns.push(i);\n var s = ns.map(x => x.toString()).join('');\n for (const c of s)\n ans += (c == '7');\n return ans;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "fizzBuzz"} -{"task_id": "JavaScript/37", "prompt": "/*This function takes a list l and returns a list l' such that\n l' is identical to l in the odd indicies, while its values at the even indicies are equal\n to the values of the even indicies of l, but sorted.\n >>> sortEven([1, 2, 3])\n [1, 2, 3]\n >>> sortEven([5, 6, 3, 4])\n [3, 6, 5, 4]\n */\nconst sortEven = (l) => {\n", "canonical_solution": " var even = l.filter((item, index) => index % 2 == 0);\n even.sort((a, b) => (a - b));\n return l.map((item, index) => (index % 2 == 0 ? even[index / 2] : item));\n}\n\n", "test": "const testSortEven = () => {\n console.assert(JSON.stringify(sortEven([1, 2, 3])) ===\n JSON.stringify([1, 2, 3]))\n console.assert(JSON.stringify(\n sortEven([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) ===\n JSON.stringify([-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123]))\n console.assert(JSON.stringify(\n sortEven([5, 8, -12, 4, 23, 2, 3, 11, 12, -10])) ===\n JSON.stringify([-12, 8, 3, 4, 5, 2, 12, 11, 23, -10]))\n}\n\ntestSortEven()\n", "declaration": "\nconst sortEven = (l) => {\n", "example_test": "const testSortEven = () => {\n console.assert(JSON.stringify(sortEven([1, 2, 3])) ===\n JSON.stringify([1, 2, 3]))\n console.assert(JSON.stringify(\n sortEven([5,6,3,4])) ===\n JSON.stringify([3,6,5,4]))\n}\ntestSortEven()\n", "buggy_solution": " var even = l.filter((item, index) => index % 2 == 0);\n l.sort((a, b) => (a - b));\n return l.map((item, index) => (index % 2 == 0 ? even[index / 2] : item));\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "sortEven"} -{"task_id": "JavaScript/38", "prompt": "/*\n returns encoded string by cycling groups of three characters.\n */\nconst encodeCyclic = (s) => {\n var groups = [], groups2 = [];\n for (let i = 0; i < Math.floor((s.length + 2) / 3); i++) {\n groups.push(s.slice(3 * i, Math.min((3 * i + 3), s.length)));\n }\n for (const group of groups) {\n if (group.length == 3)\n groups2.push(group.slice(1) + group[0]);\n else\n groups2.push(group);\n }\n return groups2.join('');\n}\n\n/*\n takes as input string encoded with encode_cyclic function. Returns decoded string.\n */\nconst decodeCyclic = (s) => {\n", "canonical_solution": " return encodeCyclic(encodeCyclic(s));\n}\n\n", "test": "const testDecodeCyclic = () => {\n const letters = new Array(26)\n .fill(null)\n .map((v, i) => String.fromCharCode(97 + i));\n\n for (let i = 0; i < 100; i++) {\n let str = new Array(Math.floor(Math.random() * 20)).fill(null);\n str = str.map(item => letters[Math.floor(Math.random() * letters.length)]).join('');\n let encoded_str = encodeCyclic(str);\n console.assert(decodeCyclic(encoded_str) === str);\n }\n}\n\ntestDecodeCyclic()\n", "declaration": "const encodeCyclic = (s) => {\n var groups = [], groups2 = [];\n for (let i = 0; i < Math.floor((s.length + 2) / 3); i++) {\n groups.push(s.slice(3 * i, Math.min((3 * i + 3), s.length)));\n }\n for (const group of groups) {\n if (group.length == 3)\n groups2.push(group.slice(1) + group[0]);\n else\n groups2.push(group);\n }\n return groups2.join('');\n}\n\nconst decodeCyclic = (s) => {\n", "example_test": "", "buggy_solution": " return encodeCyclic(s);\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "decodeCyclic"} -{"task_id": "JavaScript/39", "prompt": "/*\n primeFib returns n-th number that is a Fibonacci number and it's also prime.\n >>> primeFib(1)\n 2\n >>> primeFib(2)\n 3\n >>> primeFib(3)\n 5\n >>> primeFib(4)\n 13\n >>> primeFib(5)\n 89\n */\nconst primeFib = (n) => {\n", "canonical_solution": " var isPrime = function (p) {\n if (p < 2)\n return false;\n for (let k = 2; k < Math.min(Math.floor(Math.sqrt(p)) + 1, p - 1); k++) {\n if (p % k == 0)\n return false;\n }\n return true;\n }\n\n var f = [0, 1];\n while (true) {\n f.push(f.at(-1) + f.at(-2));\n if (isPrime(f.at(-1)))\n n -= 1;\n if (n == 0)\n return f.at(-1);\n }\n}\n\n", "test": "const testPrimeFib = () => {\n console.assert(primeFib(1) === 2)\n console.assert(primeFib(2) === 3)\n console.assert(primeFib(3) === 5)\n console.assert(primeFib(4) === 13)\n console.assert(primeFib(5) === 89)\n console.assert(primeFib(6) === 233)\n console.assert(primeFib(7) === 1597)\n console.assert(primeFib(8) === 28657)\n console.assert(primeFib(9) === 514229)\n console.assert(primeFib(10) === 433494437)\n}\n\ntestPrimeFib()\n", "declaration": "\nconst primeFib = (n) => {\n", "example_test": "const testPrimeFib = () => {\n console.assert(primeFib(1) === 2)\n console.assert(primeFib(2) === 3)\n console.assert(primeFib(3) === 5)\n console.assert(primeFib(4) === 13)\n console.assert(primeFib(5) === 89)\n}\ntestPrimeFib()\n", "buggy_solution": " var isPrime = function (p) {\n if (p < 2)\n return false;\n for (let k = 2; k < Math.min(Math.floor(Math.sqrt(p)), p); k++) {\n if (p % k == 0)\n return false;\n }\n return true;\n }\n\n var f = [0, 1];\n while (true) {\n f.push(f.at(-1) + f.at(-2));\n if (isPrime(f.at(-1)))\n n -= 1;\n if (n == 0)\n return f.at(-1);\n }\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "primeFib"} -{"task_id": "JavaScript/40", "prompt": "/*\n triplesSumToZero takes a list of integers as an input.\n it returns true if there are three distinct elements in the list that\n sum to zero, and false otherwise.\n\n >>> triplesSumToZero([1, 3, 5, 0])\n false\n >>> triplesSumToZero([1, 3, -2, 1])\n true\n >>> triplesSumToZero([1, 2, 3, 7])\n false\n >>> triplesSumToZero([2, 4, -5, 3, 9, 7])\n true\n >>> triplesSumToZero([1])\n false\n */\nconst triplesSumToZero = (l) => {\n", "canonical_solution": " for (let i = 0; i < l.length; i++)\n for (let j = i + 1; j < l.length; j++)\n for (let k = j + 1; k < l.length; k++)\n if (l[i] + l[j] + l[k] == 0)\n return true;\n return false;\n}\n\n", "test": "const testTriplesSumToZero = () => {\n console.assert(triplesSumToZero([1, 3, 5, 0]) === false)\n console.assert(triplesSumToZero([1, 3, 5, -1]) === false)\n console.assert(triplesSumToZero([1, 3, -2, 1]) === true)\n console.assert(triplesSumToZero([1, 2, 3, 7]) === false)\n console.assert(triplesSumToZero([1, 2, 5, 7]) === false)\n console.assert(triplesSumToZero([2, 4, -5, 3, 9, 7]) === true)\n console.assert(triplesSumToZero([1]) === false)\n console.assert(triplesSumToZero([1, 3, 5, -100]) === false)\n console.assert(triplesSumToZero([100, 3, 5, -100]) === false)\n}\n\ntestTriplesSumToZero()\n", "declaration": "\nconst triplesSumToZero = (l) => {\n", "example_test": "const testTriplesSumToZero = () => {\n console.assert(triplesSumToZero([1, 3, 5, 0]) === false)\n console.assert(triplesSumToZero([1, 3, -2, 1]) === true)\n console.assert(triplesSumToZero([1, 2, 3, 7]) === false)\n console.assert(triplesSumToZero([2, 4, -5, 3, 9, 7]) === true)\n}\ntestTriplesSumToZero()\n", "buggy_solution": " for (let i = 1; i < l.length; i++)\n for (let j = i + 1; j < l.length; j++)\n for (let k = j + 1; k < l.length; k++)\n if (l[i] + l[j] + l[k] == 0)\n return true;\n return false;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "triplesSumToZero"} -{"task_id": "JavaScript/41", "prompt": "/*\n Imagine a road that's a perfectly straight infinitely long line.\n n cars are driving left to right; simultaneously, a different set of n cars\n are driving right to left. The two sets of cars start out being very far from\n each other. All cars move in the same speed. Two cars are said to collide\n when a car that's moving left to right hits a car that's moving right to left.\n However, the cars are infinitely sturdy and strong; as a result, they continue moving\n in their trajectory as if they did not collide.\n\n This function outputs the number of such collisions.\n */\nconst carRaceCollision = (n) => {\n", "canonical_solution": " return Math.pow(n, 2);\n}\n\n", "test": "const testCarRaceCollision = () => {\n console.assert(carRaceCollision(2) === 4)\n console.assert(carRaceCollision(3) === 9)\n console.assert(carRaceCollision(4) === 16)\n console.assert(carRaceCollision(8) === 64)\n console.assert(carRaceCollision(10) === 100)\n}\n\ntestCarRaceCollision()\n", "declaration": "\nconst carRaceCollision = (n) => {\n", "example_test": "", "buggy_solution": " return Math.pow(n, 3);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "carRaceCollision"} -{"task_id": "JavaScript/42", "prompt": "/*Return list with elements incremented by 1.\n >>> incrList([1, 2, 3])\n [2, 3, 4]\n >>> incrList([5, 3, 5, 2, 3, 3, 9, 0, 123])\n [6, 4, 6, 3, 4, 4, 10, 1, 124]\n */\nconst incrList = (l) => {\n", "canonical_solution": " return l.map(e => e + 1);\n}\n\n", "test": "const testIncrList = () => {\n console.assert(JSON.stringify(incrList([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(incrList([3, 2, 1])) === JSON.stringify([4, 3, 2])\n )\n console.assert(\n JSON.stringify(incrList([5, 2, 5, 2, 3, 3, 9, 0, 123])) ===\n JSON.stringify([6, 3, 6, 3, 4, 4, 10, 1, 124])\n )\n}\n\ntestIncrList()\n", "declaration": "\nconst incrList = (l) => {\n", "example_test": "const testIncrList = () => {\n console.assert(\n JSON.stringify(incrList([1, 2, 3])) === JSON.stringify([2, 3, 4])\n )\n console.assert(\n JSON.stringify(incrList([5, 2, 5, 2, 3, 3, 9, 0, 123])) ===\n JSON.stringify([6, 3, 6, 3, 4, 4, 10, 1, 124])\n )\n}\ntestIncrList()\n", "buggy_solution": " return l.map(e => e + 2);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "incrList"} -{"task_id": "JavaScript/43", "prompt": "/*\n pairsSumToZero takes a list of integers as an input.\n it returns true if there are two distinct elements in the list that\n sum to zero, and false otherwise.\n >>> pairsSumToZero([1, 3, 5, 0])\n false\n >>> pairsSumToZero([1, 3, -2, 1])\n false\n >>> pairsSumToZero([1, 2, 3, 7])\n false\n >>> pairsSumToZero([2, 4, -5, 3, 5, 7])\n true\n >>> pairsSumToZero([1])\n false\n */\nconst pairsSumToZero = (l) => {\n", "canonical_solution": " for (let i = 0; i < l.length; i++)\n for (let j = i + 1; j < l.length; j++)\n if (l[i] + l[j] == 0)\n return true;\n return false;\n}\n\n", "test": "const testPairsSumToZero = () => {\n console.assert(pairsSumToZero([1, 3, 5, 0]) === false)\n console.assert(pairsSumToZero([1, 3, -2, 1]) === false)\n console.assert(pairsSumToZero([1, 2, 3, 7]) === false)\n console.assert(pairsSumToZero([2, 4, -5, 3, 5, 7]) === true)\n console.assert(pairsSumToZero([1]) === false)\n console.assert(pairsSumToZero([-3, 9, -1, 3, 2, 30]) === true)\n console.assert(pairsSumToZero([-3, 9, -1, 3, 2, 31]) === true)\n console.assert(pairsSumToZero([-3, 9, -1, 4, 2, 30]) === false)\n console.assert(pairsSumToZero([-3, 9, -1, 4, 2, 31]) === false)\n}\n\ntestPairsSumToZero()\n", "declaration": "\nconst pairsSumToZero = (l) => {\n", "example_test": "const testPairsSumToZero = () => {\n console.assert(pairsSumToZero([1, 3, 5, 0]) === false)\n console.assert(pairsSumToZero([1, 3, -2, 1]) === false)\n console.assert(pairsSumToZero([1, 2, 3, 7]) === false)\n console.assert(pairsSumToZero([2, 4, -5, 3, 5, 7]) === true)\n}\ntestPairsSumToZero()\n", "buggy_solution": " for (let i = 0; i < l.length; i++)\n for (let j = i; j < l.length; j++)\n if (l[i] + l[j] == 0)\n return true;\n return false;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "pairsSumToZero"} -{"task_id": "JavaScript/44", "prompt": "/*Change numerical base of input number x to base.\n return string representation after the conversion.\n base numbers are less than 10.\n >>> changeBase(8, 3)\n '22'\n >>> changeBase(8, 2)\n '1000'\n >>> changeBase(7, 2)\n '111'\n */\nconst changeBase = (x, base) => {\n", "canonical_solution": " var ret = \"\";\n while (x > 0) {\n ret = (x % base).toString() + ret;\n x = Math.floor(x / base);\n }\n return ret;\n}\n\n", "test": "const testChangeBase = () => {\n console.assert(changeBase(8, 3) === '22')\n console.assert(changeBase(9, 3) === '100')\n console.assert(changeBase(234, 2) === '11101010')\n console.assert(changeBase(16, 2) === '10000')\n console.assert(changeBase(8, 2) === '1000')\n console.assert(changeBase(7, 2) === '111')\n\n for (let i = 2; i < 8; i++) {\n console.assert(changeBase(i, i + 1) === i.toString())\n }\n}\n\ntestChangeBase()\n", "declaration": "\nconst changeBase = (x, base) => {\n", "example_test": "const testChangeBase = () => {\n console.assert(changeBase(8, 3) === '22')\n console.assert(changeBase(8, 2) === '1000')\n console.assert(changeBase(7, 2) === '111')\n}\ntestChangeBase()\n", "buggy_solution": " var ret = \"\";\n while (x > 0) {\n ret = (x % base).toString() + ret;\n x = Math.floor(x - base);\n }\n return ret;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "infinite loop", "entry_point": "changeBase"} -{"task_id": "JavaScript/45", "prompt": "/*Given length of a side and high return area for a triangle.\n >>> triangleArea(5, 3)\n 7.5\n */\nconst triangleArea = (a, h) => {\n", "canonical_solution": " return a * h / 2.0;\n}\n\n", "test": "const testTriangleArea = () => {\n console.assert(triangleArea(5, 3) === 7.5)\n console.assert(triangleArea(2, 2) === 2.0)\n console.assert(triangleArea(10, 8) === 40.0)\n}\n\ntestTriangleArea()\n", "declaration": "\nconst triangleArea = (a, h) => {\n", "example_test": "const testTriangleArea = () => {\n console.assert(triangleArea(5, 3) === 7.5)\n}\ntestTriangleArea()\n", "buggy_solution": " return a * h / 0.5;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "triangleArea"} -{"task_id": "JavaScript/46", "prompt": "/*The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\n fib4(0) -> 0\n fib4(1) -> 0\n fib4(2) -> 2\n fib4(3) -> 0\n fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).\n Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.\n >>> fib4(5)\n 4\n >>> fib4(6)\n 8\n >>> fib4(7)\n 14\n */\nconst fib4 = (n) => {\n", "canonical_solution": " var results = [0, 0, 2, 0];\n if (n < 4)\n return results[n];\n for (let i = 4; i < n + 1; i++) {\n results.push(results.at(-1) + results.at(-2) +\n results.at(-3) + results.at(-4));\n results.shift();\n }\n return results.pop();\n}\n\n", "test": "const testFib4 = () => {\n console.assert(fib4(5) === 4)\n console.assert(fib4(8) === 28)\n console.assert(fib4(10) === 104)\n console.assert(fib4(12) === 386)\n}\n\ntestFib4()\n", "declaration": "\nconst fib4 = (n) => {\n", "example_test": "const testFib4 = () => {\n console.assert(fib4(5) === 4)\n console.assert(fib4(6) === 8)\n console.assert(fib4(7) === 14)\n}\ntestFib4()\n", "buggy_solution": " var results = [0, 0, 2, 0];\n if (n < 4)\n return results[n];\n for (let i = 4; i < n + 1; i++) {\n results.push(results.at(-1) + results.at(-2) +\n results.at(-3) + results.at(-4));\n results.shift();\n }\n return results.at(-2);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "fib4"} -{"task_id": "JavaScript/47", "prompt": "/*Return median of elements in the list l.\n >>> median([3, 1, 2, 4, 5])\n 3\n >>> median([-10, 4, 6, 1000, 10, 20])\n 8.0\n */\nconst median = (l) => {\n", "canonical_solution": " l.sort((a, b) => a - b);\n var len = l.length;\n if (l.length % 2 == 1)\n return l[Math.floor(len / 2)];\n else\n return (l[len / 2 - 1] + l[len / 2]) / 2.0;\n}\n\n", "test": "const testMedian = () => {\n console.assert(median([3, 1, 2, 4, 5]) === 3)\n console.assert(median([-10, 4, 6, 1000, 10, 20]) === 8.0)\n console.assert(median([5]) === 5)\n console.assert(median([6, 5]) === 5.5)\n console.assert(median([8, 1, 3, 9, 9, 2, 7]) === 7)\n}\n\ntestMedian()\n", "declaration": "\nconst median = (l) => {\n", "example_test": "const testMedian = () => {\n console.assert(median([3, 1, 2, 4, 5]) === 3)\n console.assert(median([-10, 4, 6, 1000, 10, 20]) === 8.0)\n}\ntestMedian()\n", "buggy_solution": " l.sort((a, b) => a - b);\n var len = l.length;\n if (l.length % 2 == 1)\n return l[Math.floor(len / 2)];\n else\n return (l[len - 1 / 2] + l[len / 2]) / 2.0;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "median"} -{"task_id": "JavaScript/48", "prompt": "/*\n Checks if given string is a palindrome\n >>> isPalindrome('')\n true\n >>> isPalindrome('aba')\n true\n >>> isPalindrome('aaaaa')\n true\n >>> isPalindrome('zbcd')\n false\n */\nconst isPalindrome = (text) => {\n", "canonical_solution": " for (let i = 0; i < text.length; i++)\n if (text[i] != text.at(-i-1))\n return false;\n return true;\n}\n\n", "test": "const testIsPalindrome = () => {\n console.assert(isPalindrome('') === true)\n console.assert(isPalindrome('aba') === true)\n console.assert(isPalindrome('aaaaa') === true)\n console.assert(isPalindrome('zbcd') === false)\n console.assert(isPalindrome('xywyx') === true)\n console.assert(isPalindrome('xywyz') === false)\n console.assert(isPalindrome('xywzx') === false)\n}\n\ntestIsPalindrome()\n", "declaration": "\nconst isPalindrome = (text) => {\n", "example_test": "const testIsPalindrome = () => {\n console.assert(isPalindrome('') === true)\n console.assert(isPalindrome('aba') === true)\n console.assert(isPalindrome('aaaaa') === true)\n console.assert(isPalindrome('zbcd') === false)\n}\ntestIsPalindrome()\n", "buggy_solution": " for (let i = 0; i < text.length; i++)\n if (text[i] != text.at(-i))\n return false;\n return true;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "isPalindrome"} -{"task_id": "JavaScript/49", "prompt": "/*Return 2^n modulo p (be aware of numerics).\n >>> modp(3, 5)\n 3\n >>> modp(1101, 101)\n 2\n >>> modp(0, 101)\n 1\n >>> modp(3, 11)\n 8\n >>> modp(100, 101)\n 1\n */\nconst modp = (n, p) => {\n", "canonical_solution": " var ret = 1;\n for (let i = 0; i < n; i++)\n ret = (2 * ret) % p;\n return ret;\n}\n\n", "test": "const testModp = () => {\n console.assert(modp(3, 5) === 3)\n console.assert(modp(1101, 101) === 2)\n console.assert(modp(0, 101) === 1)\n console.assert(modp(3, 11) === 8)\n console.assert(modp(100, 101) === 1)\n console.assert(modp(30, 5) === 4)\n console.assert(modp(31, 5) === 3)\n}\n\ntestModp()\n", "declaration": "\nconst modp = (n, p) => {\n", "example_test": "const testModp = () => {\n console.assert(modp(3, 5) === 3)\n console.assert(modp(1101, 101) === 2)\n console.assert(modp(0, 101) === 1)\n console.assert(modp(3, 11) === 8)\n console.assert(modp(100, 101) === 1)\n}\ntestModp()\n", "buggy_solution": " var ret = 0;\n for (let i = 0; i < n; i++)\n ret = (2 * ret) % p;\n return ret;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "modp"} -{"task_id": "JavaScript/50", "prompt": "/*\n returns encoded string by shifting every character by 5 in the alphabet.\n */\nconst encodeShift = (s) => {\n return s.split(\"\").map(ch => String.fromCharCode(\n ((ch.charCodeAt(0) + 5 - \"a\".charCodeAt(0)) % 26) + \"a\".charCodeAt(0)\n )).join(\"\");\n}\n\n/*\n takes as input string encoded with encode_shift function. Returns decoded string.\n */\nconst decodeShift = (s) => {\n", "canonical_solution": " return s.split(\"\").map(ch => String.fromCharCode(\n ((ch.charCodeAt(0) - 5 + 26 - \"a\".charCodeAt(0)) % 26) + \"a\".charCodeAt(0)\n )).join(\"\");\n}\n\n", "test": "const testDecodeShift = () => {\n const letters = new Array(26)\n .fill(null)\n .map((v, i) => String.fromCharCode(97 + i))\n\n for (let i = 0; i < 100; i++) {\n let str = new Array(Math.floor(Math.random() * 20)).fill(null);\n str = str.map(item => letters[Math.floor(Math.random() * letters.length)]).join('');\n let encoded_str = encodeShift(str)\n console.assert(decodeShift(encoded_str) === str)\n }\n\n}\n\ntestDecodeShift()\n", "declaration": "const encodeShift = (s) => {\n return s.split(\"\").map(ch => String.fromCharCode(\n ((ch.charCodeAt(0) + 5 - \"a\".charCodeAt(0)) % 26) + \"a\".charCodeAt(0)\n )).join(\"\");\n}\n\nconst decodeShift = (s) => {\n", "example_test": "", "buggy_solution": " return s.split(\"\").map(ch => String.fromCharCode(\n ((ch.charCodeAt(0) - 5 + 26 - \"a\".charCodeAt(0)) % 26) + ch.charCodeAt(0)\n )).join(\"\");\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "decodeShift"} -{"task_id": "JavaScript/51", "prompt": "/*\n removeVowels is a function that takes string and returns string without vowels.\n >>> removeVowels('')\n ''\n >>> removeVowels(\"abcdef\\nghijklm\")\n 'bcdf\\nghjklm'\n >>> removeVowels('abcdef')\n 'bcdf'\n >>> removeVowels('aaaaa')\n ''\n >>> removeVowels('aaBAA')\n 'B'\n >>> removeVowels('zbcd')\n 'zbcd'\n */\nconst removeVowels = (text) => {\n", "canonical_solution": " return text.split(\"\")\n .filter(s => ![\"a\", \"e\", \"i\", \"o\", \"u\"]\n .includes(s.toLowerCase())\n )\n .join(\"\")\n}\n\n", "test": "const testRemoveVowels = () => {\n console.assert(removeVowels('') === '')\n console.assert(removeVowels('abcdef\\nghijklm') === 'bcdf\\nghjklm')\n console.assert(removeVowels('fedcba') === 'fdcb')\n console.assert(removeVowels('eeeee') === '')\n console.assert(removeVowels('acBAA') === 'cB')\n console.assert(removeVowels('EcBOO') === 'cB')\n console.assert(removeVowels('ybcd') === 'ybcd')\n}\n\ntestRemoveVowels()\n", "declaration": "\nconst removeVowels = (text) => {\n", "example_test": "const testRemoveVowels = () => {\n console.assert(removeVowels('') === '')\n console.assert(removeVowels('abcdef\\nghijklm') === 'bcdf\\nghjklm')\n console.assert(removeVowels('abcdef') === 'bcdf')\n console.assert(removeVowels('aaaaa') === '')\n console.assert(removeVowels('aaBAA') === 'B')\n console.assert(removeVowels('zbcd') === 'zbcd')\n}\ntestRemoveVowels()\n", "buggy_solution": " return text.split(\"\")\n .filter(s => ![\"a\", \"e\", \"i\", \"o\", \"u\", \"w\", \"y\"]\n .includes(s.toLowerCase())\n )\n .join(\"\")\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "removeVowels"} -{"task_id": "JavaScript/52", "prompt": "/*Return true if all numbers in the list l are below threshold t.\n >>> belowThreshold([1, 2, 4, 10], 100)\n true\n >>> belowThreshold([1, 20, 4, 10], 5)\n false\n */\nconst belowThreshold = (l, t) => {\n", "canonical_solution": " for (const e of l)\n if (e >= t)\n return false;\n return true;\n}\n\n", "test": "const testBelowThreshold = () => {\n console.assert(belowThreshold([1, 2, 4, 10], 100) === true)\n console.assert(belowThreshold([1, 20, 4, 10], 5) === false)\n console.assert(belowThreshold([1, 20, 4, 10], 21) === true)\n console.assert(belowThreshold([1, 20, 4, 10], 22) === true)\n console.assert(belowThreshold([1, 8, 4, 10], 11) === true)\n console.assert(belowThreshold([1, 8, 4, 10], 10) === false)\n}\n\ntestBelowThreshold()\n", "declaration": "\nconst belowThreshold = (l, t) => {\n", "example_test": "const testBelowThreshold = () => {\n console.assert(belowThreshold([1, 2, 4, 10], 100) === true)\n console.assert(belowThreshold([1, 20, 4, 10], 5) === false)\n}\ntestBelowThreshold()\n", "buggy_solution": " for (const e of l)\n if (e >= t)\n return true;\n return false;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "belowThreshold"} -{"task_id": "JavaScript/53", "prompt": "/*Add two numbers x and y\n >>> add(2, 3)\n 5\n >>> add(5, 7)\n 12\n */\nconst add = (x, y) => {\n", "canonical_solution": " return x + y;\n}\n\n", "test": "const testAdd = () => {\n const getRandomIntInclusive = (min = 0, max = 9) => {\n min = Math.ceil(min)\n max = Math.floor(max)\n return Math.floor(Math.random() * (max - min + 1)) + min //\u542b\u6700\u5927\u503c\uff0c\u542b\u6700\u5c0f\u503c\n }\n\n console.assert(add(0, 1) === 1)\n console.assert(add(1, 0) === 1)\n console.assert(add(2, 3) === 5)\n console.assert(add(5, 7) === 12)\n console.assert(add(7, 5) === 12)\n\n for (let i = 0; i < 100; i++) {\n let x = getRandomIntInclusive()\n let y = getRandomIntInclusive()\n console.assert(x + y === add(x, y))\n }\n}\n\ntestAdd()\n", "declaration": "\nconst add = (x, y) => {\n", "example_test": "const testAdd = () => {\n const getRandomIntInclusive = (min = 0, max = 9) => {\n min = Math.ceil(min)\n max = Math.floor(max)\n return Math.floor(Math.random() * (max - min + 1)) + min //\u542b\u6700\u5927\u503c\uff0c\u542b\u6700\u5c0f\u503c\n }\n console.assert(add(2, 3) === 5)\n console.assert(add(5, 7) === 12)\n}\ntestAdd()\n", "buggy_solution": " return x + y + y + x;\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "add"} -{"task_id": "JavaScript/54", "prompt": "/*\n Check if two words have the same characters.\n >>> sameChars('eabcdzzzz', 'dddzzzzzzzddeddabc')\n true\n >>> sameChars('abcd', 'dddddddabc')\n true\n >>> sameChars('dddddddabc', 'abcd')\n true\n >>> sameChars('eabcd', 'dddddddabc')\n false\n >>> sameChars('abcd', 'dddddddabce')\n false\n >>> sameChars('eabcdzzzz', 'dddzzzzzzzddddabc')\n false\n */\nconst sameChars = (s0, s1) => {\n", "canonical_solution": " return JSON.stringify([...new Set(s0)].sort()) === JSON.stringify([...new Set(s1)].sort());\n}\n\n", "test": "const testSameChars = () => {\n console.assert(sameChars('eabcdzzzz', 'dddzzzzzzzddeddabc') === true)\n console.assert(sameChars('abcd', 'dddddddabc') === true)\n console.assert(sameChars('dddddddabc', 'abcd') === true)\n console.assert(sameChars('eabcd', 'dddddddabc') === false)\n console.assert(sameChars('abcd', 'dddddddabcf') === false)\n console.assert(sameChars('eabcdzzzz', 'dddzzzzzzzddddabc') === false)\n console.assert(sameChars('aabb', 'aaccc') === false)\n}\n\ntestSameChars()\n", "declaration": "\nconst sameChars = (s0, s1) => {\n", "example_test": "const testSameChars = () => {\n console.assert(sameChars('eabcdzzzz', 'dddzzzzzzzddeddabc') === true)\n console.assert(sameChars('abcd', 'dddddddabc') === true)\n console.assert(sameChars('dddddddabc', 'abcd') === true)\n console.assert(sameChars('eabcd', 'dddddddabc') === false)\n console.assert(sameChars('abcd', 'dddddddabcf') === false)\n console.assert(sameChars('eabcdzzzz', 'dddzzzzzzzddddabc') === false)\n}\ntestSameChars()\n", "buggy_solution": " return JSON.stringify([...new Set(s0)]) === JSON.stringify([...new Set(s1)]);\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sameChars"} -{"task_id": "JavaScript/55", "prompt": "/*Return n-th Fibonacci number.\n >>> fib(10)\n 55\n >>> fib(1)\n 1\n >>> fib(8)\n 21\n */\nconst fib = (n) => {\n", "canonical_solution": " if (n == 0)\n return 0;\n if (n == 1)\n return 1;\n return fib(n - 1) + fib(n - 2);\n}\n\n", "test": "const testFib = () => {\n console.assert(fib(10) === 55)\n console.assert(fib(1) === 1)\n console.assert(fib(8) === 21)\n console.assert(fib(11) === 89)\n console.assert(fib(12) === 144)\n}\n\ntestFib()\n", "declaration": "\nconst fib = (n) => {\n", "example_test": "const testFib = () => {\n console.assert(fib(10) === 55)\n console.assert(fib(1) === 1)\n console.assert(fib(8) === 21)\n}\ntestFib()\n", "buggy_solution": " if (n == 0)\n return 0;\n if (n == 1)\n return 1;\n if (n == 2)\n return 2;\n return fib(n - 1) + fib(n - 2);\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "fib"} -{"task_id": "JavaScript/56", "prompt": "/* brackets is a string of \"<\" and \">\".\n return false if every opening bracket has a corresponding closing bracket.\n\n >>> correctBracketing(\"<\")\n false\n >>> correctBracketing(\"<>\")\n false\n >>> correctBracketing(\"<<><>>\")\n false\n >>> correctBracketing(\"><<>\")\n false\n */\nconst correctBracketing = (brackets) => {\n", "canonical_solution": " var depth = 0;\n for (const b of brackets) {\n if (b == \"<\")\n depth += 1;\n else\n depth -= 1;\n if (depth < 0)\n return false;\n }\n return depth == 0;\n}\n\n", "test": "const testCorrectBracketing = () => {\n console.assert(correctBracketing('<>') === true)\n console.assert(correctBracketing('<<><>>') === true)\n console.assert(correctBracketing('<><><<><>><>') === true)\n console.assert(correctBracketing('<><><<<><><>><>><<><><<>>>') === true)\n console.assert(correctBracketing('<<<><>>>>') === false)\n console.assert(correctBracketing('><<>') === false)\n console.assert(correctBracketing('<') === false)\n console.assert(correctBracketing('<<<<') === false)\n console.assert(correctBracketing('>') === false)\n console.assert(correctBracketing('<<>') === false)\n console.assert(correctBracketing('<><><<><>><>><<>') === false)\n console.assert(correctBracketing('<><><<><>><>>><>') === false)\n}\n\ntestCorrectBracketing()\n", "declaration": "\nconst correctBracketing = (brackets) => {\n", "example_test": "const testCorrectBracketing = () => {\n console.assert(correctBracketing('<>') === true)\n console.assert(correctBracketing('<<><>>') === true)\n console.assert(correctBracketing('><<>') === false)\n console.assert(correctBracketing('<') === false)\n}\ntestCorrectBracketing()\n", "buggy_solution": " var depth = 0;\n for (const b of brackets) {\n if (b == \">\")\n depth += 1;\n else\n depth -= 1;\n if (depth < 0)\n return false;\n }\n return depth == 0;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "correctBracketing"} -{"task_id": "JavaScript/57", "prompt": "/*Return true is list elements are monotonically increasing or decreasing.\n >>> monotonic([1, 2, 4, 20])\n true\n >>> monotonic([1, 20, 4, 10])\n false\n >>> monotonic([4, 1, 0, -10])\n true\n */\nconst monotonic = (l) => {\n", "canonical_solution": " var sort1 = [...l].sort((a, b) => a - b);\n var sort2 = [...l].sort((a, b) => b - a);\n if (JSON.stringify(l) === JSON.stringify(sort1) ||\n JSON.stringify(l) === JSON.stringify(sort2))\n return true;\n return false;\n}\n\n", "test": "const testMonotonic = () => {\n console.assert(monotonic([1, 2, 4, 10]) === true)\n console.assert(monotonic([1, 2, 4, 20]) === true)\n console.assert(monotonic([1, 20, 4, 10]) === false)\n console.assert(monotonic([4, 1, 0, -10]) === true)\n console.assert(monotonic([4, 1, 1, 0]) === true)\n console.assert(monotonic([1, 2, 3, 2, 5, 60]) === false)\n console.assert(monotonic([1, 2, 3, 4, 5, 60]) === true)\n console.assert(monotonic([9, 9, 9, 9]) === true)\n}\n\ntestMonotonic()\n", "declaration": "\nconst monotonic = (l) => {\n", "example_test": "const testMonotonic = () => {\n console.assert(monotonic([1, 2, 4, 10]) === true)\n console.assert(monotonic([1, 20, 4, 10]) === false)\n console.assert(monotonic([4, 1, 0, -10]) === true)\n}\ntestMonotonic()\n", "buggy_solution": " var sort1 = [...l].sort((a, b) => a - b);\n var sort2 = [...l].sort((a, b) => b - a);\n if (JSON.stringify(l) === JSON.stringify(sort1) ||\n JSON.stringify(l) === JSON.stringify(sort2))\n return false;\n return true;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "monotonic"} -{"task_id": "JavaScript/58", "prompt": "/*Return sorted unique common elements for two lists.\n >>> common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121])\n [1, 5, 653]\n >>> common([5, 3, 2, 8], [3, 2])\n [2, 3]\n\n */\nconst common = (l1, l2) => {\n", "canonical_solution": " var ret = new Set();\n for (const e1 of l1)\n for (const e2 of l2)\n if (e1 == e2)\n ret.add(e1);\n return [...ret].sort();\n}\n\n", "test": "const testCommon = () => {\n console.assert(\n JSON.stringify(common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]))\n === JSON.stringify([1, 5, 653])\n )\n console.assert(\n JSON.stringify(common([5, 3, 2, 8], [3, 2]))\n === JSON.stringify([2, 3])\n )\n console.assert(\n JSON.stringify(common([4, 3, 2, 8], [3, 2, 4])) ===\n JSON.stringify([2, 3, 4])\n )\n console.assert(\n JSON.stringify(common([4, 3, 2, 8], [])) === JSON.stringify([])\n )\n}\n\ntestCommon()\n", "declaration": "\nconst common = (l1, l2) => {\n", "example_test": "const testCommon = () => {\n console.assert(\n JSON.stringify(common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]))\n === JSON.stringify([1, 5, 653])\n )\n console.assert(\n JSON.stringify(common([5, 3, 2, 8], [3, 2]))\n === JSON.stringify([2, 3])\n )\n}\ntestCommon()\n", "buggy_solution": " var ret = new Set();\n for (const e1 of l1)\n for (const e2 of l2)\n ret.add(e1);\n return [...ret].sort();\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "common"} -{"task_id": "JavaScript/59", "prompt": "/*Return the largest prime factor of n. Assume n > 1 and is not a prime.\n >>> largestPrimeFactor(13195)\n 29\n >>> largestPrimeFactor(2048)\n 2\n */\nconst largestPrimeFactor = (n) => {\n", "canonical_solution": " var isPrime = function (k) {\n if (k < 2)\n return false;\n for (let i = 2; i < k - 1; i++)\n if (k % i == 0)\n return false;\n return true;\n }\n\n var largest = 1;\n for (let j = 2; j < n + 1; j++)\n if (n % j == 0 && isPrime(j))\n largest = Math.max(largest, j);\n return largest;\n}\n\n", "test": "const testLargestPrimeFactor = () => {\n console.assert(largestPrimeFactor(15) === 5)\n console.assert(largestPrimeFactor(27) === 3)\n console.assert(largestPrimeFactor(63) === 7)\n console.assert(largestPrimeFactor(330) === 11)\n console.assert(largestPrimeFactor(13195) === 29)\n}\n\ntestLargestPrimeFactor()\n", "declaration": "\nconst largestPrimeFactor = (n) => {\n", "example_test": "const testLargestPrimeFactor = () => {\n console.assert(largestPrimeFactor(2048) === 2)\n console.assert(largestPrimeFactor(13195) === 29)\n}\ntestLargestPrimeFactor()\n", "buggy_solution": " var isPrime = function (k) {\n if (k < 2)\n return false;\n for (let i = 2; i < k - 1; i++)\n if (k % i == 0)\n return false;\n return true;\n }\n\n var largest = 1;\n for (let j = 2; j < n + 1; j++)\n if (n % j == 0 && isPrime(n))\n largest = Math.max(largest, j);\n return largest;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "largestPrimeFactor"} -{"task_id": "JavaScript/60", "prompt": "/*sumToN is a function that sums numbers from 1 to n.\n >>> sumToN(30)\n 465\n >>> sumToN(100)\n 5050\n >>> sumToN(5)\n 15\n >>> sumToN(10)\n 55\n >>> sumToN(1)\n 1\n */\nconst sumToN = (n) => {\n", "canonical_solution": " return n * (n + 1) / 2;\n}\n\n", "test": "const testSumToN = () => {\n console.assert(sumToN(1) === 1)\n console.assert(sumToN(6) === 21)\n console.assert(sumToN(11) === 66)\n console.assert(sumToN(30) === 465)\n console.assert(sumToN(100) === 5050)\n}\n\ntestSumToN()\n", "declaration": "\nconst sumToN = (n) => {\n", "example_test": "const testSumToN = () => {\n console.assert(sumToN(1) === 1)\n console.assert(sumToN(5) === 15)\n console.assert(sumToN(10) === 55)\n console.assert(sumToN(30) === 465)\n console.assert(sumToN(100) === 5050)\n}\ntestSumToN()\n", "buggy_solution": " return n * n / 2;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "sumToN"} -{"task_id": "JavaScript/61", "prompt": "/* brackets is a string of \"(\" and \")\".\n return true if every opening bracket has a corresponding closing bracket.\n\n >>> correctBracketing(\"(\")\n false\n >>> correctBracketing(\"()\")\n true\n >>> correctBracketing(\"(()())\")\n true\n >>> correctBracketing(\")(()\")\n false\n */\nconst correctBracketing = (brackets) => {\n", "canonical_solution": " var depth = 0;\n for (const b of brackets) {\n if (b == \"(\")\n depth += 1;\n else\n depth -= 1;\n if (depth < 0)\n return false;\n }\n return depth == 0;\n}\n\n", "test": "const testCorrectBracketing = () => {\n console.assert(correctBracketing('()') === true)\n console.assert(correctBracketing('(()())') === true)\n console.assert(correctBracketing('()()(()())()') === true)\n console.assert(correctBracketing('()()((()()())())(()()(()))') === true)\n console.assert(correctBracketing('((()())))') === false)\n console.assert(correctBracketing(')(()') === false)\n console.assert(correctBracketing('(') === false)\n console.assert(correctBracketing('((((') === false)\n console.assert(correctBracketing(')') === false)\n console.assert(correctBracketing('(()') === false)\n console.assert(correctBracketing('()()(()())())(()') === false)\n console.assert(correctBracketing('()()(()())()))()') === false)\n}\n\ntestCorrectBracketing()\n", "declaration": "\nconst correctBracketing = (brackets) => {\n", "example_test": "const testCorrectBracketing = () => {\n console.assert(correctBracketing('()') === true)\n console.assert(correctBracketing('(()())') === true)\n console.assert(correctBracketing(')(()') === false)\n console.assert(correctBracketing('(') === false)\n}\ntestCorrectBracketing()\n", "buggy_solution": " var depth = 0;\n for (const b of brackets) {\n if (b == \"(\")\n depth += 1;\n else\n depth -= 1;\n if (depth < 0)\n return true;\n }\n return depth == 0;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "correctBracketing"} -{"task_id": "JavaScript/62", "prompt": "/* xs represent coefficients of a polynomial.\n xs[0] + xs[1] * x + xs[2] * x^2 + ....\n Return derivative of this polynomial in the same form.\n >>> derivative([3, 1, 2, 4, 5])\n [1, 4, 12, 20]\n >>> derivative([1, 2, 3])\n [2, 6]\n */\nconst derivative = (xs) => {\n", "canonical_solution": " return xs.map((x, i) => x * i).slice(1);\n}\n\n", "test": "const testDerivative = () => {\n console.assert(\n JSON.stringify(derivative([3, 1, 2, 4, 5])) ===\n JSON.stringify([1, 4, 12, 20])\n )\n console.assert(\n JSON.stringify(derivative([1, 2, 3])) === JSON.stringify([2, 6])\n )\n console.assert(\n JSON.stringify(derivative([3, 2, 1])) === JSON.stringify([2, 2])\n )\n console.assert(\n JSON.stringify(derivative([3, 2, 1, 0, 4])) ===\n JSON.stringify([2, 2, 0, 16])\n )\n console.assert(JSON.stringify(derivative([1])) === JSON.stringify([]))\n}\n\ntestDerivative()\n", "declaration": "\nconst derivative = (xs) => {\n", "example_test": "const testDerivative = () => {\n console.assert(\n JSON.stringify(derivative([3, 1, 2, 4, 5])) ===\n JSON.stringify([1, 4, 12, 20])\n )\n console.assert(\n JSON.stringify(derivative([1, 2, 3])) === JSON.stringify([2, 6])\n )\n}\ntestDerivative()\n", "buggy_solution": " return xs.map((x, i) => x * i);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "derivative"} -{"task_id": "JavaScript/63", "prompt": "/*The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\n fibfib(0) == 0\n fibfib(1) == 0\n fibfib(2) == 1\n fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).\n Please write a function to efficiently compute the n-th element of the fibfib number sequence.\n >>> fibfib(1)\n 0\n >>> fibfib(5)\n 4\n >>> fibfib(8)\n 24\n */\nconst fibfib = (n) => {\n", "canonical_solution": " if (n == 0 || n == 1)\n return 0;\n if (n == 2)\n return 1;\n return fibfib(n - 1) + fibfib(n - 2) + fibfib(n - 3);\n}\n\n", "test": "const testFibfib = () => {\n console.assert(fibfib(2) === 1)\n console.assert(fibfib(1) === 0)\n console.assert(fibfib(5) === 4)\n console.assert(fibfib(8) === 24)\n console.assert(fibfib(10) === 81)\n console.assert(fibfib(12) === 274)\n console.assert(fibfib(14) === 927)\n}\n\ntestFibfib()\n", "declaration": "\nconst fibfib = (n) => {\n", "example_test": "const testFibfib = () => {\n console.assert(fibfib(1) === 0)\n console.assert(fibfib(5) === 4)\n console.assert(fibfib(8) === 24)\n}\ntestFibfib()\n", "buggy_solution": " if (n == 0 || n == 1)\n return n;\n if (n == 2)\n return 2;\n return fibfib(n - 1) + fibfib(n - 2) + fibfib(n - 3);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "fibfib"} -{"task_id": "JavaScript/64", "prompt": "/*Write a function vowelsCount which takes a string representing\n a word as input and returns the number of vowels in the string.\n Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a\n vowel, but only when it is at the end of the given word.\n\n Example:\n >>> vowelsCount(\"abcde\")\n 2\n >>> vowelsCount(\"ACEDY\")\n 3\n */\nconst vowelsCount = (s) => {\n", "canonical_solution": " var vowels = \"aeiouAEIOU\";\n var n_vowels = s.split('').reduce((prev, item) => {\n return prev + (vowels.includes(item));\n }, 0);\n if (s.at(-1) == 'y' || s.at(-1) == 'Y')\n n_vowels += 1;\n return n_vowels;\n}\n\n", "test": "const testVowelsCount = () => {\n console.assert(vowelsCount('abcde') === 2)\n console.assert(vowelsCount('Alone') === 3)\n console.assert(vowelsCount('key') === 2)\n console.assert(vowelsCount('bye') === 1)\n console.assert(vowelsCount('keY') === 2)\n console.assert(vowelsCount('bYe') === 1)\n console.assert(vowelsCount('ACEDY') === 3)\n}\n\ntestVowelsCount()\n", "declaration": "\nconst vowelsCount = (s) => {\n", "example_test": "const testVowelsCount = () => {\n console.assert(vowelsCount('abcde') === 2)\n console.assert(vowelsCount('ACEDY') === 3)\n}\ntestVowelsCount()\n", "buggy_solution": " var vowels = \"aeiouyAEIOUY\";\n var n_vowels = s.split('').reduce((prev, item) => {\n return prev + (vowels.includes(item));\n }, 0);\n return n_vowels;\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "vowelsCount"} -{"task_id": "JavaScript/65", "prompt": "/*Circular shift the digits of the integer x, shift the digits right by shift\n and return the result as a string.\n If shift > number of digits, return digits reversed.\n >>> circularShift(12, 1)\n \"21\"\n >>> circularShift(12, 2)\n \"12\"\n */\nconst circularShift = (x, shift) => {\n", "canonical_solution": " s = x.toString();\n if (shift > s.length)\n return s.split('').reverse().join('');\n else\n return s.slice(-shift) + s.slice(0, -shift);\n}\n\n", "test": "const testCircularShift = () => {\n console.assert(circularShift(100, 2) === '001')\n console.assert(circularShift(12, 2) === '12')\n console.assert(circularShift(97, 8) === '79')\n console.assert(circularShift(12, 1) === '21')\n console.assert(circularShift(11, 101) === '11')\n}\n\ntestCircularShift()\n", "declaration": "\nconst circularShift = (x, shift) => {\n", "example_test": "const testCircularShift = () => {\n console.assert(circularShift(12, 2) === '12')\n console.assert(circularShift(12, 1) === '21')\n}\ntestCircularShift()\n", "buggy_solution": " s = x.toString();\n if (shift > s.length)\n return s.split('').reverse().join('');\n else\n return s.slice(0, -shift) + s.slice(-shift);\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "circularShift"} -{"task_id": "JavaScript/66", "prompt": "/*Task\n Write a function that takes a string as input and returns the sum of the upper characters only'\n ASCII codes.\n\n Examples:\n digitSum(\"\") => 0\n digitSum(\"abAB\") => 131\n digitSum(\"abcCd\") => 67\n digitSum(\"helloE\") => 69\n digitSum(\"woArBld\") => 131\n digitSum(\"aAaaaXa\") => 153\n */\nconst digitSum = (s) => {\n", "canonical_solution": " if (s == '') return 0;\n return s.split('').reduce((prev, char) => {\n let ord_char = char.charCodeAt(0)\n return prev + (ord_char > 64 && ord_char < 91 ? ord_char : 0);\n }, 0);\n}\n\n", "test": "const testDigitSum = () => {\n console.assert(digitSum('') === 0)\n console.assert(digitSum('abAB') === 131)\n console.assert(digitSum('abcCd') === 67)\n console.assert(digitSum('helloE') === 69)\n console.assert(digitSum('woArBld') === 131)\n console.assert(digitSum('aAaaaXa') === 153)\n console.assert(digitSum(' How are yOu?') === 151)\n console.assert(digitSum('You arE Very Smart') === 327)\n}\n\ntestDigitSum()\n", "declaration": "\nconst digitSum = (s) => {\n", "example_test": "const testDigitSum = () => {\n console.assert(digitSum('') === 0)\n console.assert(digitSum('abAB') === 131)\n console.assert(digitSum('abcCd') === 67)\n console.assert(digitSum('helloE') === 69)\n console.assert(digitSum('woArBld') === 131)\n console.assert(digitSum('aAaaaXa') === 153)\n}\ntestDigitSum()\n", "buggy_solution": " if (s == '') return 0;\n return s.split('').reduce((prev, char) => {\n let ord_char = char.charCodeAt(0)\n return prev + (ord_char > 64 && ord_char < 100 ? ord_char : 0);\n }, 0);\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "digitSum"} -{"task_id": "JavaScript/67", "prompt": "/*\n In this task, you will be given a string that represents a number of apples and oranges\n that are distributed in a basket of fruit this basket contains\n apples, oranges, and mango fruits. Given the string that represents the total number of\n the oranges and apples and an integer that represent the total number of the fruits\n in the basket return the number of the mango fruits in the basket.\n for examble:\n fruitDistribution(\"5 apples and 6 oranges\", 19) ->19 - 5 - 6 = 8\n fruitDistribution(\"0 apples and 1 oranges\",3) -> 3 - 0 - 1 = 2\n fruitDistribution(\"2 apples and 3 oranges\", 100) -> 100 - 2 - 3 = 95\n fruitDistribution(\"100 apples and 1 oranges\",120) -> 120 - 100 - 1 = 19\n */\nconst fruitDistribution = (s, n) => {\n", "canonical_solution": " var lis = [];\n for (const i of s.split(\" \"))\n if (!isNaN(i))\n lis.push(Number(i))\n return n - lis.reduce(((prev, item) => prev + item), 0);\n}\n\n", "test": "const testFruitDistribution = () => {\n console.assert(fruitDistribution('5 apples and 6 oranges', 19) === 8)\n console.assert(fruitDistribution('5 apples and 6 oranges', 21) === 10)\n console.assert(fruitDistribution('0 apples and 1 oranges', 3) === 2)\n console.assert(fruitDistribution('1 apples and 0 oranges', 3) === 2)\n console.assert(fruitDistribution('2 apples and 3 oranges', 100) === 95)\n console.assert(fruitDistribution('2 apples and 3 oranges', 5) === 0)\n console.assert(fruitDistribution('1 apples and 100 oranges', 120) === 19)\n}\n\ntestFruitDistribution()\n", "declaration": "\nconst fruitDistribution = (s, n) => {\n", "example_test": "const testFruitDistribution = () => {\n console.assert(fruitDistribution('5 apples and 6 oranges', 19) === 8)\n console.assert(fruitDistribution('0 apples and 1 oranges', 3) === 2)\n console.assert(fruitDistribution('2 apples and 3 oranges', 100) === 95)\n console.assert(fruitDistribution('1 apples and 100 oranges', 120) === 19)\n}\ntestFruitDistribution()\n", "buggy_solution": " var lis = [];\n for (const i of s.split(\" \"))\n if (!isNaN(i))\n lis.push(Number(i))\n return n - 1 - lis.reduce(((prev, item) => prev + item), 0);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "fruitDistribution"} -{"task_id": "JavaScript/68", "prompt": "/*\n \"Given an array representing a branch of a tree that has non-negative integer nodes\n your task is to pluck one of the nodes and return it.\n The plucked node should be the node with the smallest even value.\n If multiple nodes with the same smallest even value are found return the node that has smallest index.\n\n The plucked node should be returned in a list, [ smalest_value, its index ],\n If there are no even values or the given array is empty, return [].\n\n Example 1:\n Input: [4,2,3]\n Output: [2, 1]\n Explanation: 2 has the smallest even value, and 2 has the smallest index.\n\n Example 2:\n Input: [1,2,3]\n Output: [2, 1]\n Explanation: 2 has the smallest even value, and 2 has the smallest index.\n\n Example 3:\n Input: []\n Output: []\n\n Example 4:\n Input: [5, 0, 3, 0, 4, 2]\n Output: [0, 1]\n Explanation: 0 is the smallest value, but there are two zeros,\n so we will choose the first zero, which has the smallest index.\n\n Constraints:\n * 1 <= nodes.length <= 10000\n * 0 <= node.value\n */\nconst pluck = (arr) => {\n", "canonical_solution": " if (arr.length == 0) return [];\n var evens = arr.filter(x => x % 2 == 0);\n if (evens.length == 0) return [];\n return [Math.min(...evens), arr.indexOf(Math.min(...evens))];\n}\n\n", "test": "const testPluck = () => {\n console.assert(JSON.stringify(pluck([4, 2, 3])) === JSON.stringify([2, 1]))\n console.assert(JSON.stringify(pluck([1, 2, 3])) === JSON.stringify([2, 1]))\n console.assert(JSON.stringify(pluck([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(pluck([5, 0, 3, 0, 4, 2])) === JSON.stringify([0, 1])\n )\n console.assert(\n JSON.stringify(pluck([1, 2, 3, 0, 5, 3])) === JSON.stringify([0, 3])\n )\n console.assert(\n JSON.stringify(pluck([5, 4, 8, 4, 8])) === JSON.stringify([4, 1])\n )\n console.assert(JSON.stringify(pluck([7, 6, 7, 1])) === JSON.stringify([6, 1]))\n console.assert(JSON.stringify(pluck([7, 9, 7, 1])) === JSON.stringify([]))\n}\n\ntestPluck()\n", "declaration": "\nconst pluck = (arr) => {\n", "example_test": "const testPluck = () => {\n console.assert(JSON.stringify(pluck([4, 2, 3])) === JSON.stringify([2, 1]))\n console.assert(JSON.stringify(pluck([1, 2, 3])) === JSON.stringify([2, 1]))\n console.assert(JSON.stringify(pluck([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(pluck([5, 0, 3, 0, 4, 2])) === JSON.stringify([0, 1])\n )\n}\ntestPluck()\n", "buggy_solution": " if (arr.length == 0) return [];\n var evens = arr.filter(x => x % 2 == 0);\n if (evens.length == 0) return [];\n return [arr.indexOf(Math.min(...evens)), Math.min(...evens)];\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "pluck"} -{"task_id": "JavaScript/69", "prompt": "/*\n You are given a non-empty list of positive integers. Return the greatest integer that is greater than\n zero, and has a frequency greater than or equal to the value of the integer itself.\n The frequency of an integer is the number of times it appears in the list.\n If no such a value exist, return -1.\n Examples:\n search([4, 1, 2, 2, 3, 1])) == 2\n search([1, 2, 2, 3, 3, 3, 4, 4, 4])) == 3\n search([5, 5, 4, 4, 4])) == -1\n */\nconst search = (lst) => {\n", "canonical_solution": " var frq = new Array(Math.max(...lst) + 1).fill(0);\n for (const i of lst)\n frq[i] += 1;\n var ans = -1;\n for (let i = 1; i < frq.length; i++)\n if (frq[i] >= i)\n ans = i;\n return ans;\n}\n\n", "test": "const testSearch = () => {\n console.assert(search([5, 5, 5, 5, 1]) === 1)\n console.assert(search([4, 1, 4, 1, 4, 4]) === 4)\n console.assert(search([3, 3]) === -1)\n console.assert(search([8, 8, 8, 8, 8, 8, 8, 8]) === 8)\n console.assert(search([2, 3, 3, 2, 2]) === 2)\n console.assert(\n search([\n 2, 7, 8, 8, 4, 8, 7, 3, 9, 6, 5, 10, 4, 3, 6, 7, 1, 7, 4, 10, 8, 1,\n ]) === 1\n )\n console.assert(search([3, 2, 8, 2]) === 2)\n console.assert(search([6, 7, 1, 8, 8, 10, 5, 8, 5, 3, 10]) === 1)\n console.assert(search([8, 8, 3, 6, 5, 6, 4]) === -1)\n console.assert(\n search([\n 6, 9, 6, 7, 1, 4, 7, 1, 8, 8, 9, 8, 10, 10, 8, 4, 10, 4, 10, 1, 2, 9, 5,\n 7, 9,\n ]) === 1\n )\n console.assert(search([1, 9, 10, 1, 3]) === 1)\n console.assert(\n search([\n 6, 9, 7, 5, 8, 7, 5, 3, 7, 5, 10, 10, 3, 6, 10, 2, 8, 6, 5, 4, 9, 5, 3,\n 10,\n ]) === 5\n )\n console.assert(search([1]) === 1)\n console.assert(\n search([\n 8, 8, 10, 6, 4, 3, 5, 8, 2, 4, 2, 8, 4, 6, 10, 4, 2, 1, 10, 2, 1, 1, 5,\n ]) === 4\n )\n console.assert(\n search([2, 10, 4, 8, 2, 10, 5, 1, 2, 9, 5, 5, 6, 3, 8, 6, 4, 10]) === 2\n )\n console.assert(search([1, 6, 10, 1, 6, 9, 10, 8, 6, 8, 7, 3]) === 1)\n console.assert(\n search([\n 9, 2, 4, 1, 5, 1, 5, 2, 5, 7, 7, 7, 3, 10, 1, 5, 4, 2, 8, 4, 1, 9, 10, 7,\n 10, 2, 8, 10, 9, 4,\n ]) === 4\n )\n console.assert(\n search([\n 2, 6, 4, 2, 8, 7, 5, 6, 4, 10, 4, 6, 3, 7, 8, 8, 3, 1, 4, 2, 2, 10, 7,\n ]) === 4\n )\n console.assert(\n search([9, 8, 6, 10, 2, 6, 10, 2, 7, 8, 10, 3, 8, 2, 6, 2, 3, 1]) === 2\n )\n console.assert(\n search([\n 5, 5, 3, 9, 5, 6, 3, 2, 8, 5, 6, 10, 10, 6, 8, 4, 10, 7, 7, 10, 8,\n ]) === -1\n )\n console.assert(search([10]) === -1)\n console.assert(search([9, 7, 7, 2, 4, 7, 2, 10, 9, 7, 5, 7, 2]) === 2)\n console.assert(search([5, 4, 10, 2, 1, 1, 10, 3, 6, 1, 8]) === 1)\n console.assert(\n search([\n 7, 9, 9, 9, 3, 4, 1, 5, 9, 1, 2, 1, 1, 10, 7, 5, 6, 7, 6, 7, 7, 6,\n ]) === 1\n )\n console.assert(search([3, 10, 10, 9, 2]) === -1)\n}\n\ntestSearch()\n", "declaration": "\nconst search = (lst) => {\n", "example_test": "const testSearch = () => {\n console.assert(search([4, 1, 2, 2, 3, 1]) === 2)\n console.assert(search([1, 2, 2, 3, 3, 3, 4, 4, 4]) === 3)\n console.assert(search([5, 5, 4, 4, 4]) === -1)\n}\ntestSearch()\n", "buggy_solution": " var frq = new Array(Math.max(...lst) + 1).fill(0);\n for (const i of lst)\n frq[i] += 1;\n var ans = 0;\n for (let i = 1; i < frq.length; i++)\n if (frq[i] >= i)\n ans = i;\n return ans;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "search"} -{"task_id": "JavaScript/70", "prompt": "/*\n Given list of integers, return list in strange order.\n Strange sorting, is when you start with the minimum value,\n then maximum of the remaining integers, then minimum and so on.\n\n Examples:\n strangeSortList([1, 2, 3, 4]) == [1, 4, 2, 3]\n strangeSortList([5, 5, 5, 5]) == [5, 5, 5, 5]\n strangeSortList([]) == []\n */\nconst strangeSortList = (lst) => {\n", "canonical_solution": " var res = [], sw = true;\n while (lst.length) {\n res.push(sw ? Math.min(...lst) : Math.max(...lst));\n lst.splice(lst.indexOf(res.at(-1)), 1);\n sw = !sw;\n }\n return res;\n}\n\n", "test": "const testStrangeSortList = () => {\n console.assert(\n JSON.stringify(strangeSortList([1, 2, 3, 4])) ===\n JSON.stringify([1, 4, 2, 3])\n )\n console.assert(\n JSON.stringify(strangeSortList([5, 6, 7, 8, 9])) ===\n JSON.stringify([5, 9, 6, 8, 7])\n )\n console.assert(\n JSON.stringify(strangeSortList([1, 2, 3, 4, 5])) ===\n JSON.stringify([1, 5, 2, 4, 3])\n )\n console.assert(\n JSON.stringify(strangeSortList([5, 6, 7, 8, 9, 1])) ===\n JSON.stringify([1, 9, 5, 8, 6, 7])\n )\n console.assert(\n JSON.stringify(strangeSortList([5, 5, 5, 5])) ===\n JSON.stringify([5, 5, 5, 5])\n )\n console.assert(JSON.stringify(strangeSortList([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(strangeSortList([1, 2, 3, 4, 5, 6, 7, 8])) ===\n JSON.stringify([1, 8, 2, 7, 3, 6, 4, 5])\n )\n console.assert(\n JSON.stringify(strangeSortList([0, 2, 2, 2, 5, 5, -5, -5])) ===\n JSON.stringify([-5, 5, -5, 5, 0, 2, 2, 2])\n )\n console.assert(\n JSON.stringify(strangeSortList([111111])) === JSON.stringify([111111])\n )\n}\n\ntestStrangeSortList()\n", "declaration": "\nconst strangeSortList = (lst) => {\n", "example_test": "const testStrangeSortList = () => {\n console.assert(\n JSON.stringify(strangeSortList([1, 2, 3, 4])) ===\n JSON.stringify([1, 4, 2, 3])\n )\n console.assert(\n JSON.stringify(strangeSortList([5, 5, 5, 5])) ===\n JSON.stringify([5, 5, 5, 5])\n )\n console.assert(JSON.stringify(strangeSortList([])) === JSON.stringify([]))\n}\ntestStrangeSortList()\n", "buggy_solution": " var res = [], sw = false;\n while (lst.length) {\n res.push(sw ? Math.min(...lst) : Math.max(...lst));\n lst.splice(lst.indexOf(res.at(-1)), 1);\n sw = !sw;\n }\n return res;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "strangeSortList"} -{"task_id": "JavaScript/71", "prompt": "/*\n Given the lengths of the three sides of a triangle. Return the area of\n the triangle rounded to 2 decimal points if the three sides form a valid triangle.\n Otherwise return -1\n Three sides make a valid triangle when the sum of any two sides is greater\n than the third side.\n Example:\n triangleArea(3, 4, 5) == 6.00\n triangleArea(1, 2, 10) == -1\n */\nconst triangleArea = (a, b, c) => {\n", "canonical_solution": " if (a + b <= c || a + c <= b || b + c <= a)\n return -1;\n var s = (a + b + c) / 2;\n var area = Math.pow(s * (s - a) * (s - b) * (s - c), 0.5);\n area = area.toFixed(2);\n return area;\n}\n\n", "test": "const testTriangleArea = () => {\n console.assert(triangleArea(3, 4, 5) == 6.0)\n console.assert(triangleArea(1, 2, 10) == -1)\n console.assert(triangleArea(4, 8, 5) == 8.18)\n console.assert(triangleArea(2, 2, 2) == 1.73)\n console.assert(triangleArea(1, 2, 3) == -1)\n console.assert(triangleArea(10, 5, 7) == 16.25)\n console.assert(triangleArea(2, 6, 3) == -1)\n console.assert(triangleArea(1, 1, 1) == 0.43)\n console.assert(triangleArea(2, 2, 10) == -1)\n}\n\ntestTriangleArea()\n", "declaration": "\nconst triangleArea = (a, b, c) => {\n", "example_test": "const testTriangleArea = () => {\n console.assert(triangleArea(3, 4, 5) == 6.0)\n console.assert(triangleArea(1, 2, 10) == -1)\n}\ntestTriangleArea()\n", "buggy_solution": " if (a + b <= c || a + c <= b || b + c <= a)\n return -1;\n var s = (a + b + c);\n var area = Math.pow(s * (s - a) * (s - b) * (s - c), 0.5);\n area = area.toFixed(2);\n return area;\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "triangleArea"} -{"task_id": "JavaScript/72", "prompt": "/*\n Write a function that returns true if the object q will fly, and false otherwise.\n The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w.\n\n Example:\n willItFly([1, 2], 5) \u279e false\n # 1+2 is less than the maximum possible weight, but it's unbalanced.\n\n willItFly([3, 2, 3], 1) \u279e false\n # it's balanced, but 3+2+3 is more than the maximum possible weight.\n\n willItFly([3, 2, 3], 9) \u279e true\n # 3+2+3 is less than the maximum possible weight, and it's balanced.\n\n willItFly([3], 5) \u279e true\n # 3 is less than the maximum possible weight, and it's balanced.\n */\nconst willItFly = (q, w) => {\n", "canonical_solution": " if (q.reduce(((prev, item) => prev + item), 0) > w)\n return false;\n var i = 0, j = q.length - 1;\n while (i < j) {\n if (q[i] != q[j])\n return false;\n i++;\n j--;\n }\n return true;\n}\n\n", "test": "const testWillItFly = () => {\n console.assert(willItFly([3, 2, 3], 9) === true)\n console.assert(willItFly([1, 2], 5) === false)\n console.assert(willItFly([3], 5) === true)\n console.assert(willItFly([3, 2, 3], 1) === false)\n console.assert(willItFly([1, 2, 3], 6) === false)\n console.assert(willItFly([5], 5) === true)\n}\n\ntestWillItFly()\n", "declaration": "\nconst willItFly = (q, w) => {\n", "example_test": "const testWillItFly = () => {\n console.assert(willItFly([3, 2, 3], 9) === true)\n console.assert(willItFly([1, 2], 5) === false)\n console.assert(willItFly([3], 5) === true)\n console.assert(willItFly([3, 2, 3], 1) === false)\n}\ntestWillItFly()\n", "buggy_solution": " if (q.reduce(((prev, item) => prev + item), 0) > w)\n return false;\n var i = 0, j = q.length - 1;\n while (i < j) {\n if (q[i] == q[j])\n return false;\n i++;\n j--;\n }\n return true;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "willItFly"} -{"task_id": "JavaScript/73", "prompt": "/*\n Given an array arr of integers, find the minimum number of elements that\n need to be changed to make the array palindromic. A palindromic array is an array that\n is read the same backwards and forwards. In one change, you can change one element to any other element.\n\n For example:\n smallestChange([1,2,3,5,4,7,9,6]) == 4\n smallestChange([1, 2, 3, 4, 3, 2, 2]) == 1\n smallestChange([1, 2, 3, 2, 1]) == 0\n */\nconst smallestChange = (arr) => {\n", "canonical_solution": " var ans = 0;\n for (let i = 0; i < Math.floor(arr.length / 2); i++)\n if (arr[i] != arr.at(-i - 1))\n ans++;\n return ans;\n}\n\n", "test": "const testSmallestChange = () => {\n console.assert(smallestChange([1, 2, 3, 5, 4, 7, 9, 6]) === 4)\n console.assert(smallestChange([1, 2, 3, 4, 3, 2, 2]) === 1)\n console.assert(smallestChange([1, 4, 2]) === 1)\n console.assert(smallestChange([1, 4, 4, 2]) === 1)\n console.assert(smallestChange([1, 2, 3, 2, 1]) === 0)\n console.assert(smallestChange([3, 1, 1, 3]) === 0)\n console.assert(smallestChange([1]) === 0)\n console.assert(smallestChange([0, 1]) === 1)\n}\n\ntestSmallestChange()\n", "declaration": "\nconst smallestChange = (arr) => {\n", "example_test": "const testSmallestChange = () => {\n console.assert(smallestChange([1, 2, 3, 5, 4, 7, 9, 6]) === 4)\n console.assert(smallestChange([1, 2, 3, 4, 3, 2, 2]) === 1)\n console.assert(smallestChange([1, 2, 3, 2, 1]) === 0)\n console.assert(smallestChange([3, 1, 1, 3]) === 0)\n}\ntestSmallestChange()\n", "buggy_solution": " var ans = 0;\n for (let i = 0; i < Math.floor(arr.length / 2); i++)\n if (ans != arr.at(-i - 1))\n ans++;\n return ans;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "smallestChange"} -{"task_id": "JavaScript/74", "prompt": "/*\n Write a function that accepts two lists of strings and returns the list that has\n total number of chars in the all strings of the list less than the other list.\n\n if the two lists have the same number of chars, return the first list.\n\n Examples\n totalMatch([], []) \u279e []\n totalMatch(['hi', 'admin'], ['hI', 'Hi']) \u279e ['hI', 'Hi']\n totalMatch(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) \u279e ['hi', 'admin']\n totalMatch(['hi', 'admin'], ['hI', 'hi', 'hi']) \u279e ['hI', 'hi', 'hi']\n totalMatch(['4'], ['1', '2', '3', '4', '5']) \u279e ['4']\n */\nconst totalMatch = (lst1, lst2) => {\n", "canonical_solution": " var l1 = lst1.reduce(((prev, item) => prev + item.length), 0);\n var l2 = lst2.reduce(((prev, item) => prev + item.length), 0);\n if (l1 <= l2)\n return lst1;\n else\n return lst2;\n}\n\n", "test": "const testTotalMatch = () => {\n console.assert(JSON.stringify(totalMatch([], [])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(totalMatch(['hi', 'admin'], ['hi', 'hi'])) ===\n JSON.stringify(['hi', 'hi'])\n )\n console.assert(\n JSON.stringify(\n totalMatch(['hi', 'admin'], ['hi', 'hi', 'admin', 'project'])\n ) === JSON.stringify(['hi', 'admin'])\n )\n console.assert(\n JSON.stringify(totalMatch(['4'], ['1', '2', '3', '4', '5'])) ===\n JSON.stringify(['4'])\n )\n console.assert(\n JSON.stringify(totalMatch(['hi', 'admin'], ['hI', 'Hi'])) ===\n JSON.stringify(['hI', 'Hi'])\n )\n console.assert(\n JSON.stringify(totalMatch(['hi', 'admin'], ['hI', 'hi', 'hi'])) ===\n JSON.stringify(['hI', 'hi', 'hi'])\n )\n console.assert(\n JSON.stringify(totalMatch(['hi', 'admin'], ['hI', 'hi', 'hii'])) ===\n JSON.stringify(['hi', 'admin'])\n )\n console.assert(\n JSON.stringify(totalMatch([], ['this'])) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(totalMatch(['this'], [])) === JSON.stringify([])\n )\n}\n\ntestTotalMatch()\n", "declaration": "\nconst totalMatch = (lst1, lst2) => {\n", "example_test": "const testTotalMatch = () => {\n console.assert(JSON.stringify(totalMatch([], [])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(\n totalMatch(['hi', 'admin'], ['hi', 'hi', 'admin', 'project'])\n ) === JSON.stringify(['hi', 'admin'])\n )\n console.assert(\n JSON.stringify(totalMatch(['4'], ['1', '2', '3', '4', '5'])) ===\n JSON.stringify(['4'])\n )\n console.assert(\n JSON.stringify(totalMatch(['hi', 'admin'], ['hI', 'Hi'])) ===\n JSON.stringify(['hI', 'Hi'])\n )\n console.assert(\n JSON.stringify(totalMatch(['hi', 'admin'], ['hI', 'hi', 'hi'])) ===\n JSON.stringify(['hI', 'hi', 'hi'])\n )\n}\ntestTotalMatch()\n", "buggy_solution": " var l1 = lst1.reduce(((prev, item) => prev + item.length), 0);\n var l2 = lst2.reduce(((prev, item) => prev + item.length), 0);\n if (l1 <= l2)\n return lst2;\n else\n return lst1;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "totalMatch"} -{"task_id": "JavaScript/75", "prompt": "/*Write a function that returns true if the given number is the multiplication of 3 prime numbers\n and false otherwise.\n Knowing that (a) is less then 100.\n Example:\n isMultiplyPrime(30) == true\n 30 = 2 * 3 * 5\n */\nconst isMultiplyPrime = (a) => {\n", "canonical_solution": " var isPrime = function (n) {\n for (let j = 2; j < n; j++)\n if (n % j == 0)\n return false;\n return true;\n }\n\n for (let i = 2; i < 101; i++) {\n if (!isPrime(i)) continue;\n for (let j = 2; j < 101; j++) {\n if (!isPrime(j)) continue;\n for (let k = 2; k < 101; k++) {\n if (!isPrime(k)) continue;\n if (i*j*k == a)\n return true;\n }\n }\n }\n return false;\n}\n\n", "test": "const testIsMultiplyPrime = () => {\n console.assert(isMultiplyPrime(5) === false)\n console.assert(isMultiplyPrime(30) === true)\n console.assert(isMultiplyPrime(8) === true)\n console.assert(isMultiplyPrime(10) === false)\n console.assert(isMultiplyPrime(125) === true)\n console.assert(isMultiplyPrime(3 * 5 * 7) === true)\n console.assert(isMultiplyPrime(3 * 6 * 7) === false)\n console.assert(isMultiplyPrime(9 * 9 * 9) === false)\n console.assert(isMultiplyPrime(11 * 9 * 9) === false)\n console.assert(isMultiplyPrime(11 * 13 * 7) === true)\n}\n\ntestIsMultiplyPrime()\n", "declaration": "\nconst isMultiplyPrime = (a) => {\n", "example_test": "const testIsMultiplyPrime = () => {\n console.assert(isMultiplyPrime(30) === true)\n}\ntestIsMultiplyPrime()\n", "buggy_solution": " var isPrime = function (n) {\n for (let j = 0; j < n; j++)\n if (n % j == 0)\n return false;\n return true;\n }\n\n for (let i = 2; i < 101; i++) {\n if (!isPrime(i)) continue;\n for (let j = 2; j < 101; j++) {\n if (!isPrime(j)) continue;\n for (let k = 2; k < 101; k++) {\n if (!isPrime(k)) continue;\n if (i*j*k == a)\n return true;\n }\n }\n }\n return false;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "isMultiplyPrime"} -{"task_id": "JavaScript/76", "prompt": "/*Your task is to write a function that returns true if a number x is a simple\n power of n and false in other cases.\n x is a simple power of n if n**int=x\n For example:\n isSimplePower(1, 4) => true\n isSimplePower(2, 2) => true\n isSimplePower(8, 2) => true\n isSimplePower(3, 2) => false\n isSimplePower(3, 1) => false\n isSimplePower(5, 3) => false\n */\nconst isSimplePower = (x, n) => {\n", "canonical_solution": " if (n == 1)\n return (x == 1);\n var power = 1;\n while (power < x)\n power = power * n;\n return (power == x);\n}\n\n", "test": "const testIsSimplePower = () => {\n console.assert(isSimplePower(1, 4) === true)\n console.assert(isSimplePower(2, 2) === true)\n console.assert(isSimplePower(8, 2) === true)\n console.assert(isSimplePower(3, 2) === false)\n console.assert(isSimplePower(3, 1) === false)\n console.assert(isSimplePower(5, 3) === false)\n console.assert(isSimplePower(16, 2) === true)\n console.assert(isSimplePower(143214, 16) === false)\n console.assert(isSimplePower(4, 2) === true)\n console.assert(isSimplePower(9, 3) === true)\n console.assert(isSimplePower(16, 4) === true)\n console.assert(isSimplePower(24, 2) === false)\n console.assert(isSimplePower(128, 4) === false)\n console.assert(isSimplePower(12, 6) === false)\n console.assert(isSimplePower(1, 1) === true)\n console.assert(isSimplePower(1, 12) === true)\n}\n\ntestIsSimplePower()\n", "declaration": "\nconst isSimplePower = (x, n) => {\n", "example_test": "const testIsSimplePower = () => {\n console.assert(isSimplePower(1, 4) === true)\n console.assert(isSimplePower(2, 2) === true)\n console.assert(isSimplePower(8, 2) === true)\n console.assert(isSimplePower(3, 2) === false)\n console.assert(isSimplePower(3, 1) === false)\n console.assert(isSimplePower(5, 3) === false)\n}\ntestIsSimplePower()\n", "buggy_solution": " if (n == 1)\n return (x == 1);\n var power = 1;\n while (n < x)\n power = power * n;\n return (power == x);\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "infinite loop", "entry_point": "isSimplePower"} -{"task_id": "JavaScript/77", "prompt": "/*\n Write a function that takes an integer a and returns true\n if this ingeger is a cube of some integer number.\n Note: you may assume the input is always valid.\n Examples:\n iscube(1) ==> true\n iscube(2) ==> false\n iscube(-1) ==> true\n iscube(64) ==> true\n iscube(0) ==> true\n iscube(180) ==> false\n */\nconst iscube = (a) => {\n", "canonical_solution": " a = Math.abs(a);\n return (Math.pow(Math.round(Math.pow(a, 1.0 / 3.0)), 3) == a);\n}\n\n", "test": "const testIscube = () => {\n console.assert(true === iscube(1))\n console.assert(false === iscube(2))\n console.assert(true === iscube(-1))\n console.assert(true === iscube(64))\n console.assert(false === iscube(180))\n console.assert(true === iscube(1000))\n console.assert(true === iscube(0))\n console.assert(false === iscube(1729))\n}\n\ntestIscube()\n", "declaration": "\nconst iscube = (a) => {\n", "example_test": "const testIscube = () => {\n console.assert(true === iscube(1))\n console.assert(false === iscube(2))\n console.assert(true === iscube(-1))\n console.assert(true === iscube(64))\n console.assert(false === iscube(180))\n console.assert(true === iscube(0))\n}\ntestIscube()\n", "buggy_solution": " a = Math.abs(a);\n return (Math.round(Math.pow(a, 1.0 / 3.0)) == a);\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "iscube"} -{"task_id": "JavaScript/78", "prompt": "/*You have been tasked to write a function that receives\n a hexadecimal number as a string and counts the number of hexadecimal\n digits that are primes (prime number=== or a prime=== is a natural number\n greater than 1 that is not a product of two smaller natural numbers).\n Hexadecimal digits are 0=== 1=== 2=== 3=== 4=== 5=== 6=== 7=== 8=== 9=== A=== B=== C=== D=== E=== F.\n Prime numbers are 2=== 3=== 5=== 7=== 11=== 13=== 17===...\n So you have to determine a number of the following digits: 2=== 3=== 5=== 7===\n B (=decimal 11)=== D (=decimal 13).\n Note: you may assume the input is always correct or empty string===\n and symbols A===B===C===D===E===F are always uppercase.\n Examples:\n For num = \"AB\" the output should be 1.\n For num = \"1077E\" the output should be 2.\n For num = \"ABED1A33\" the output should be 4.\n For num = \"123456789ABCDEF0\" the output should be 6.\n For num = \"2020\" the output should be 2.\n */\nconst hexKey = (num) => {\n", "canonical_solution": " var primes = \"2357BD\",\n total = 0;\n for (let i = 0; i < num.length; i++)\n if (primes.includes(num[i]))\n total++;\n return total;\n}\n\n", "test": "const testHexKey = () => {\n console.assert(1 === hexKey('AB'))\n console.assert(2 === hexKey('1077E'))\n console.assert(4 === hexKey('ABED1A33'))\n console.assert(2 === hexKey('2020'))\n console.assert(6 === hexKey('123456789ABCDEF0'))\n console.assert(12 === hexKey('112233445566778899AABBCCDDEEFF00'))\n console.assert(0 === hexKey(''))\n}\n\ntestHexKey()\n", "declaration": "\nconst hexKey = (num) => {\n", "example_test": "const testHexKey = () => {\n console.assert(1 === hexKey('AB'))\n console.assert(2 === hexKey('1077E'))\n console.assert(4 === hexKey('ABED1A33'))\n console.assert(2 === hexKey('2020'))\n console.assert(6 === hexKey('123456789ABCDEF0'))\n}\ntestHexKey()\n", "buggy_solution": " var primes = \"2357BD\",\n total = 1;\n for (let i = 0; i < num.length; i++)\n if (primes.includes(num[i]))\n total++;\n return total;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "hexKey"} -{"task_id": "JavaScript/79", "prompt": "/*You will be given a number in decimal form and your task is to convert it to\n binary format. The function should return a string, with each character representing a binary\n number. Each character in the string will be '0' or '1'.\n\n There will be an extra couple of characters 'db' at the beginning and at the end of the string.\n The extra characters are there to help with the format.\n\n Examples:\n decimalToBinary(15) # returns \"db1111db\"\n decimalToBinary(32) # returns \"db100000db\"\n */\nconst decimalToBinary = (decimal) => {\n", "canonical_solution": " return \"db\" + decimal.toString(2) + \"db\";\n}\n\n", "test": "const testDecimalToBinary = () => {\n console.assert(decimalToBinary(0) === 'db0db')\n console.assert(decimalToBinary(32) === 'db100000db')\n console.assert(decimalToBinary(103) === 'db1100111db')\n console.assert(decimalToBinary(15) === 'db1111db')\n}\n\ntestDecimalToBinary()\n", "declaration": "\nconst decimalToBinary = (decimal) => {\n", "example_test": "const testDecimalToBinary = () => {\n console.assert(decimalToBinary(32) === 'db100000db')\n console.assert(decimalToBinary(15) === 'db1111db')\n}\ntestDecimalToBinary()\n", "buggy_solution": " return \"db\" + decimal.toString(2) + \"d\";\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "decimalToBinary"} -{"task_id": "JavaScript/80", "prompt": "/*You are given a string s.\n Your task is to check if the string is happy or not.\n A string is happy if its length is at least 3 and every 3 consecutive letters are distinct\n For example:\n isHappy(a) => false\n isHappy(aa) => false\n isHappy(abcd) => true\n isHappy(aabb) => false\n isHappy(adb) => true\n isHappy(xyy) => false\n */\nconst isHappy = (s) => {\n", "canonical_solution": " if (s.length < 3)\n return false;\n for (let i = 0; i < s.length - 2; i++)\n if (s[i] == s[i+1] || s[i+1] == s[i+2] || s[i] == s[i+2])\n return false;\n return true;\n}\n\n", "test": "const testIsHappy = () => {\n console.assert(isHappy('a') === false)\n console.assert(isHappy('aa') === false)\n console.assert(isHappy('abcd') === true)\n console.assert(isHappy('aabb') === false)\n console.assert(isHappy('adb') === true)\n console.assert(isHappy('xyy') === false)\n console.assert(isHappy('iopaxpoi') === true)\n console.assert(isHappy('iopaxioi') === false)\n}\n\ntestIsHappy()\n", "declaration": "\nconst isHappy = (s) => {\n", "example_test": "const testIsHappy = () => {\n console.assert(isHappy('a') === false)\n console.assert(isHappy('aa') === false)\n console.assert(isHappy('abcd') === true)\n console.assert(isHappy('aabb') === false)\n console.assert(isHappy('adb') === true)\n console.assert(isHappy('xyy') === false)\n}\ntestIsHappy()\n", "buggy_solution": " if (s.length < 3)\n return false;\n for (let i = 0; i < s.length - 2; i++)\n if (s[i] == s[i+1] && s[i+1] == s[i+2] && s[i] == s[i+2])\n return false;\n return true;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "isHappy"} -{"task_id": "JavaScript/81", "prompt": "/*It is the last week of the semester and the teacher has to give the grades\n to students. The teacher has been making her own algorithm for grading.\n The only problem is, she has lost the code she used for grading.\n She has given you a list of GPAs for some students and you have to write\n a function that can output a list of letter grades using the following table:\n GPA | Letter grade\n 4.0 A+\n > 3.7 A\n > 3.3 A-\n > 3.0 B+\n > 2.7 B\n > 2.3 B-\n > 2.0 C+\n > 1.7 C\n > 1.3 C-\n > 1.0 D+\n > 0.7 D\n > 0.0 D-\n 0.0 E\n\n\n Example:\n numericalLetterGrade([4.0, 3, 1.7, 2, 3.5]) ==> ['A+', 'B', 'C-', 'C', 'A-']\n */\nconst numericalLetterGrade = (grades) => {\n", "canonical_solution": " let letter_grade = []\n for (let i = 0, len = grades.length; i < len; i++) {\n let gpa = grades[i]\n if (gpa == 4.0) {\n letter_grade.push('A+')\n } else if (gpa > 3.7) {\n letter_grade.push('A')\n } else if (gpa > 3.3) {\n letter_grade.push('A-')\n } else if (gpa > 3.0) {\n letter_grade.push('B+')\n } else if (gpa > 2.7) {\n letter_grade.push('B')\n } else if (gpa > 2.3) {\n letter_grade.push('B-')\n } else if (gpa > 2.0) {\n letter_grade.push('C+')\n } else if (gpa > 1.7) {\n letter_grade.push('C')\n } else if (gpa > 1.3) {\n letter_grade.push('C-')\n } else if (gpa > 1.0) {\n letter_grade.push('D+')\n } else if (gpa > 0.7) {\n letter_grade.push('D')\n } else if (gpa > 0.0) {\n letter_grade.push('D-')\n } else {\n letter_grade.push('E')\n }\n }\n return letter_grade\n}\n\n", "test": "const testNumericalLetterGrade = () => {\n console.assert(\n JSON.stringify(numericalLetterGrade([4.0, 3, 1.7, 2, 3.5])) ===\n JSON.stringify(['A+', 'B', 'C-', 'C', 'A-'])\n )\n console.assert(\n JSON.stringify(numericalLetterGrade([1.2])) === JSON.stringify(['D+'])\n )\n console.assert(\n JSON.stringify(numericalLetterGrade([0.5])) === JSON.stringify(['D-'])\n )\n console.assert(\n JSON.stringify(numericalLetterGrade([0.0])) === JSON.stringify(['E'])\n )\n console.assert(\n JSON.stringify(numericalLetterGrade([1, 0.3, 1.5, 2.8, 3.3])) ===\n JSON.stringify(['D', 'D-', 'C-', 'B', 'B+'])\n )\n console.assert(\n JSON.stringify(numericalLetterGrade([0, 0.7])) ===\n JSON.stringify(['E', 'D-'])\n )\n}\n\ntestNumericalLetterGrade()\n", "declaration": "\nconst numericalLetterGrade = (grades) => {\n", "example_test": "const testNumericalLetterGrade = () => {\n console.assert(\n JSON.stringify(numericalLetterGrade([4.0, 3, 1.7, 2, 3.5])) ===\n JSON.stringify(['A+', 'B', 'C-', 'C', 'A-'])\n )\n}\ntestNumericalLetterGrade()\n", "buggy_solution": " let letter_grade = []\n for (let i = 0, len = grades.length; i < len; i++) {\n let gpa = grades[i]\n if (gpa == 4.0) {\n letter_grade.push('A+')\n } else if (gpa > 3.7) {\n letter_grade.push('A')\n } else if (gpa > 3.3) {\n letter_grade.push('A-')\n } else if (gpa > 3.0) {\n letter_grade.push('B+')\n } else if (gpa > 2.7) {\n letter_grade.push('B')\n } else if (gpa > 2.3) {\n letter_grade.push('B-')\n } else if (gpa > 2.0) {\n letter_grade.push('C+')\n } else if (gpa > 1.7) {\n letter_grade.push('C')\n } else if (gpa > 1.3) {\n letter_grade.push('C-')\n } else if (gpa > 1.0) {\n letter_grade.push('D+')\n } else if (gpa > 0.7) {\n letter_grade.push('D')\n } else if (gpa > 0.0) {\n letter_grade.push('D-')\n } else {\n letter_grade.push('E+')\n }\n }\n return letter_grade\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "numericalLetterGrade"} -{"task_id": "JavaScript/82", "prompt": "/*Write a function that takes a string and returns true if the string\n length is a prime number or false otherwise\n Examples\n primeLength('Hello') == true\n primeLength('abcdcba') == true\n primeLength('kittens') == true\n primeLength('orange') == false\n */\nconst primeLength = (string) => {\n", "canonical_solution": " let len = string.length\n if (len == 1 || len == 0) { return false }\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { return false }\n }\n return true\n}\n\n", "test": "const testPrimeLength = () => {\n console.assert(primeLength('Hello') === true)\n console.assert(primeLength('abcdcba') === true)\n console.assert(primeLength('kittens') === true)\n console.assert(primeLength('orange') === false)\n console.assert(primeLength('wow') === true)\n console.assert(primeLength('world') === true)\n console.assert(primeLength('MadaM') === true)\n console.assert(primeLength('Wow') === true)\n console.assert(primeLength('') === false)\n console.assert(primeLength('HI') === true)\n console.assert(primeLength('go') === true)\n console.assert(primeLength('gogo') === false)\n console.assert(primeLength('aaaaaaaaaaaaaaa') === false)\n console.assert(primeLength('Madam') === true)\n console.assert(primeLength('M') === false)\n console.assert(primeLength('0') === false)\n}\n\ntestPrimeLength()\n", "declaration": "\nconst primeLength = (string) => {\n", "example_test": "const testPrimeLength = () => {\n console.assert(primeLength('Hello') === true)\n console.assert(primeLength('abcdcba') === true)\n console.assert(primeLength('kittens') === true)\n console.assert(primeLength('orange') === false)\n}\ntestPrimeLength()\n", "buggy_solution": " let len = string.length\n if (len == 1 || len == 0) { return false }\n for (let i = 3; i * i <= len; i++) {\n if (len % i == 0) { return false }\n }\n return true\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "primeLength"} -{"task_id": "JavaScript/83", "prompt": "/*\n Given a positive integer n, return the count of the numbers of n-digit\n positive integers that start or end with 1.\n */\nconst startsOneEnds = (n) => {\n", "canonical_solution": " if (n == 1) { return 1 }\n let t = 18\n for (let i = 2; i < n; i++) {\n t = t * 10\n }\n return t\n}\n\n", "test": "const testStartsOneEnds = () => {\n console.assert(startsOneEnds(1) === 1)\n console.assert(startsOneEnds(2) === 18)\n console.assert(startsOneEnds(3) === 180)\n console.assert(startsOneEnds(4) === 1800)\n console.assert(startsOneEnds(5) === 18000)\n}\n\ntestStartsOneEnds()\n", "declaration": "\nconst startsOneEnds = (n) => {\n", "example_test": "", "buggy_solution": " if (n == 1) { return 1 }\n let t = 18\n for (let i = 2; i < n; i++) {\n t = t * i * 10\n }\n return t\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "startsOneEnds"} -{"task_id": "JavaScript/84", "prompt": "/*Given a positive integer N, return the total sum of its digits in binary.\n \n Example\n For N = 1000, the sum of digits will be 1 the output should be \"1\".\n For N = 150, the sum of digits will be 6 the output should be \"110\".\n For N = 147, the sum of digits will be 12 the output should be \"1100\".\n \n Variables:\n @N integer\n Constraints: 0 \u2264 N \u2264 10000.\n Output:\n a string of binary number\n */\nconst solve = (N) => {\n", "canonical_solution": " let t = 0\n while (N > 0) {\n t += N % 10\n N = (N - N % 10) / 10\n }\n return t.toString(2)\n}\n\n", "test": "const testSolve = () => {\n console.assert(solve(1000) === '1')\n console.assert(solve(150) === '110')\n console.assert(solve(147) === '1100')\n console.assert(solve(333) === '1001')\n console.assert(solve(963) === '10010')\n}\n\ntestSolve()\n", "declaration": "\nconst solve = (N) => {\n", "example_test": "", "buggy_solution": " let t = 0\n while (N > 0) {\n t = N % 10\n N = (N - N % 10) / 10\n }\n return t.toString(2)\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "solve"} -{"task_id": "JavaScript/85", "prompt": "/*Given a non-empty list of integers lst. add the even elements that are at odd indices..\n\n\n Examples:\n add([4, 2, 6, 7]) ==> 2 \n */\nconst add = (lst) => {\n", "canonical_solution": " let t = 0\n for (let i = 1; i < lst.length; i += 2) {\n if (lst[i] % 2 == 0) {\n t += lst[i]\n }\n }\n return t\n}\n\n", "test": "const testAdd = () => {\n console.assert(add([4, 88]) === 88)\n console.assert(add([4, 5, 6, 7, 2, 122]) === 122)\n console.assert(add([4, 0, 6, 7]) === 0)\n console.assert(add([4, 4, 6, 8]) === 12)\n}\n\ntestAdd()\n", "declaration": "\nconst add = (lst) => {\n", "example_test": "const testAdd = () => {\n console.assert(add([4, 2, 6, 7]) === 2)\n}\ntestAdd()\n", "buggy_solution": " let t = 0\n for (let i = 1; i < lst.length; i += 1) {\n if (lst[i] % 2 == 0) {\n t += lst[i]\n }\n }\n return t\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "add"} -{"task_id": "JavaScript/86", "prompt": "/*\n Write a function that takes a string and returns an ordered version of it.\n Ordered version of string, is a string where all words (separated by space)\n are replaced by a new word where all the characters arranged in\n ascending order based on ascii value.\n Note: You should keep the order of words and blank spaces in the sentence.\n\n For example:\n antiShuffle('Hi') returns 'Hi'\n antiShuffle('hello') returns 'ehllo'\n antiShuffle('Hello World!!!') returns 'Hello !!!Wdlor'\n */\nconst antiShuffle = (s) => {\n", "canonical_solution": " let arr = s.split(/\\s/)\n for (let i = 0; i < arr.length; i++) {\n for (let j = 0; j < arr[i].length; j++) {\n let ind = j\n for (let k = j + 1; k < arr[i].length; k++) {\n if (arr[i][k].charCodeAt() < arr[i][ind].charCodeAt()) {\n ind = k\n }\n }\n if (ind > j) {\n arr[i] = arr[i].slice(0, j) + arr[i][ind] + arr[i].slice(j + 1, ind) + arr[i][j] + arr[i].slice(ind + 1, arr[i].length)\n }\n }\n }\n let t = ''\n for (let i = 0; i < arr.length; i++) {\n if (i > 0) {\n t = t + ' '\n }\n t = t + arr[i]\n }\n return t\n}\n\n", "test": "const testAntiShuffle = () => {\n console.assert(antiShuffle('Hi') === 'Hi')\n console.assert(antiShuffle('hello') === 'ehllo')\n console.assert(antiShuffle('number') === 'bemnru')\n console.assert(antiShuffle('abcd') === 'abcd')\n console.assert(antiShuffle('Hello World!!!') === 'Hello !!!Wdlor')\n console.assert(antiShuffle('') === '')\n console.assert(\n antiShuffle('Hi. My name is Mister Robot. How are you?') ===\n '.Hi My aemn is Meirst .Rboot How aer ?ouy'\n )\n}\n\ntestAntiShuffle()\n", "declaration": "\nconst antiShuffle = (s) => {\n", "example_test": "const testAntiShuffle = () => {\n console.assert(antiShuffle('Hi') === 'Hi')\n console.assert(antiShuffle('hello') === 'ehllo')\n console.assert(antiShuffle('Hello World!!!') === 'Hello !!!Wdlor')\n}\ntestAntiShuffle()\n", "buggy_solution": " let arr = s.split(/\\s/)\n for (let i = 0; i < arr.length; i++) {\n for (let j = 0; j < arr[i].length; j++) {\n let ind = j\n for (let k = j + 1; k < arr[i].length; k++) {\n if (arr[i][k].charCodeAt() < arr[i][ind].charCodeAt()) {\n ind = k\n }\n }\n if (ind > j) {\n arr[i] = arr[i].slice(0, j) + arr[i][ind] + arr[i].slice(j + 1, ind) + arr[i][j] + arr[i].slice(ind + 1, arr[i].length)\n }\n }\n }\n let t = ''\n for (let i = 0; i < arr.length; i++) {\n t = t + arr[i]\n }\n return t\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "antiShuffle"} -{"task_id": "JavaScript/87", "prompt": "/*\n You are given a 2 dimensional data, as a nested lists,\n which is similar to matrix, however, unlike matrices,\n each row may contain a different number of columns.\n Given lst, and integer x, find integers x in the list,\n and return list of tuples, [(x1, y1), (x2, y2) ...] such that\n each tuple is a coordinate - (row, columns), starting with 0.\n Sort coordinates initially by rows in ascending order.\n Also, sort coordinates of the row by columns in descending order.\n \n Examples:\n getRow([\n [1,2,3,4,5,6],\n [1,2,3,4,1,6],\n [1,2,3,4,5,1]\n ], 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]\n getRow([], 1) == []\n getRow([[], [1], [1, 2, 3]], 3) == [(2, 2)]\n */\nconst getRow = (lst, x) => {\n", "canonical_solution": " let t = []\n for (let i = 0; i < lst.length; i++) {\n for (let j = lst[i].length - 1; j >= 0; j--) {\n if (lst[i][j] == x) {\n t.push((i, j))\n }\n }\n }\n return t\n}\n\n", "test": "const testGetRow = () => {\n console.assert(\n JSON.stringify(\n getRow(\n [\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 1, 6],\n [1, 2, 3, 4, 5, 1],\n ],\n 1\n )\n ) === JSON.stringify([(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)])\n )\n console.assert(\n JSON.stringify(\n getRow(\n [\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n ],\n 2\n )\n ) === JSON.stringify([(0, 1), (1, 1), (2, 1), (3, 1), (4, 1), (5, 1)])\n )\n console.assert(\n JSON.stringify(\n getRow(\n [\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n [1, 1, 3, 4, 5, 6],\n [1, 2, 1, 4, 5, 6],\n [1, 2, 3, 1, 5, 6],\n [1, 2, 3, 4, 1, 6],\n [1, 2, 3, 4, 5, 1],\n ],\n 1\n )\n ) ===\n JSON.stringify([\n (0, 0),\n (1, 0),\n (2, 1),\n (2, 0),\n (3, 2),\n (3, 0),\n (4, 3),\n (4, 0),\n (5, 4),\n (5, 0),\n (6, 5),\n (6, 0),\n ])\n )\n console.assert(JSON.stringify(getRow([], 1)) === JSON.stringify([]))\n console.assert(JSON.stringify(getRow([[1]], 2)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(getRow([[], [1], [1, 2, 3]], 3)) === JSON.stringify([(2, 2)])\n )\n}\n\ntestGetRow()\n", "declaration": "\nconst getRow = (lst, x) => {\n", "example_test": "const testGetRow = () => {\n console.assert(\n JSON.stringify(\n getRow(\n [\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 1, 6],\n [1, 2, 3, 4, 5, 1],\n ],\n 1\n )\n ) === JSON.stringify([(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)])\n )\n console.assert(JSON.stringify(getRow([], 1)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(getRow([[], [1], [1, 2, 3]], 3)) === JSON.stringify([(2, 2)])\n )\n}\ntestGetRow()\n", "buggy_solution": " let t = []\n for (let i = 0; i < lst.length; i++) {\n for (let j = lst[i].length - 1; j >= 0; j--) {\n if (lst[i][j] == x) {\n t.push((j, i))\n }\n }\n }\n return t\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "getRow"} -{"task_id": "JavaScript/88", "prompt": "/*\n Given an array of non-negative integers, return a copy of the given array after sorting,\n you will sort the given array in ascending order if the sum( first index value, last index value) is odd,\n or sort it in descending order if the sum( first index value, last index value) is even.\n\n Note:\n * don't change the given array.\n\n Examples:\n * sortArray([]) => []\n * sortArray([5]) => [5]\n * sortArray([2, 4, 3, 0, 1, 5]) => [0, 1, 2, 3, 4, 5]\n * sortArray([2, 4, 3, 0, 1, 5, 6]) => [6, 5, 4, 3, 2, 1, 0]\n */\nconst sortArray = (array) => {\n", "canonical_solution": " let arr = array\n let tot = arr[0] + arr[arr.length-1]\n for (let j = 0; j < arr.length; j++) {\n let ind = j\n for (let k = j + 1; k < arr.length; k++) {\n if ((tot % 2 == 1 && arr[k] < arr[ind]) || (tot % 2 == 0 && arr[k] > arr[ind])) {\n ind = k\n }\n }\n let tmp = arr[j]\n arr[j] = arr[ind]\n arr[ind] = tmp\n }\n return arr\n}\n\n", "test": "const testSortArray = () => {\n console.assert(JSON.stringify(sortArray([])) === JSON.stringify([]))\n console.assert(JSON.stringify(sortArray([5])) === JSON.stringify([5]))\n console.assert(JSON.stringify(sortArray([2, 4, 3, 0, 1, 5])) === JSON.stringify([0, 1, 2, 3, 4, 5]))\n console.assert(JSON.stringify(sortArray([2, 4, 3, 0, 1, 5, 6])) === JSON.stringify([6, 5, 4, 3, 2, 1, 0]))\n console.assert(JSON.stringify(sortArray([2, 1])) === JSON.stringify([1, 2]))\n console.assert(JSON.stringify(sortArray([15, 42, 87, 32, 11, 0])) === JSON.stringify([0, 11, 15, 32, 42, 87]))\n console.assert(JSON.stringify(sortArray([21, 14, 23, 11])) === JSON.stringify([23, 21, 14, 11]))\n}\n\ntestSortArray()\n", "declaration": "\nconst sortArray = (array) => {\n", "example_test": "const testSortArray = () => {\n console.assert(JSON.stringify(sortArray([])) === JSON.stringify([]))\n console.assert(JSON.stringify(sortArray([5])) === JSON.stringify([5]))\n console.assert(JSON.stringify(sortArray([2, 4, 3, 0, 1, 5])) === JSON.stringify([0, 1, 2, 3, 4, 5]))\n console.assert(JSON.stringify(sortArray([2, 4, 3, 0, 1, 5, 6])) === JSON.stringify([6, 5, 4, 3, 2, 1, 0]))\n}\ntestSortArray()\n", "buggy_solution": " let arr = array\n let tot = arr[0] + arr[arr.length-1]\n for (let j = 0; j < arr.length; j++) {\n let ind = j\n for (let k = j + 1; k < arr.length; k++) {\n if ((tot % 2 == 1 && arr[k] < arr[ind]) || (tot % 2 != 0 && arr[k] > arr[ind])) {\n ind = k\n }\n }\n let tmp = arr[j]\n arr[j] = arr[ind]\n arr[ind] = tmp\n }\n return arr\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "sortArray"} -{"task_id": "JavaScript/89", "prompt": "/*Create a function encrypt that takes a string as an argument and\n returns a string encrypted with the alphabet being rotated. \n The alphabet should be rotated in a manner such that the letters \n shift down by two multiplied to two places.\n For example:\n encrypt('hi') returns 'lm'\n encrypt('asdfghjkl') returns 'ewhjklnop'\n encrypt('gf') returns 'kj'\n encrypt('et') returns 'ix'\n */\nconst encrypt = (s) => {\n", "canonical_solution": " let t = ''\n for (let i = 0; i < s.length; i++) {\n let p = s[i].charCodeAt() + 4\n if (p > 122) { p -= 26 }\n t += String.fromCharCode(p)\n }\n return t\n}\n\n", "test": "const testEncrypt = () => {\n console.assert(encrypt('hi') === 'lm')\n console.assert(encrypt('asdfghjkl') === 'ewhjklnop')\n console.assert(encrypt('gf') === 'kj')\n console.assert(encrypt('et') === 'ix')\n console.assert(encrypt('faewfawefaewg') === 'jeiajeaijeiak')\n console.assert(encrypt('hellomyfriend') === 'lippsqcjvmirh')\n console.assert(\n encrypt('dxzdlmnilfuhmilufhlihufnmlimnufhlimnufhfucufh') ===\n 'hbdhpqrmpjylqmpyjlpmlyjrqpmqryjlpmqryjljygyjl'\n )\n console.assert(encrypt('a') === 'e')\n}\n\ntestEncrypt()\n", "declaration": "\nconst encrypt = (s) => {\n", "example_test": "const testEncrypt = () => {\n console.assert(encrypt('hi') === 'lm')\n console.assert(encrypt('asdfghjkl') === 'ewhjklnop')\n console.assert(encrypt('gf') === 'kj')\n console.assert(encrypt('et') === 'ix')\n}\ntestEncrypt()\n", "buggy_solution": " let t = ''\n for (let i = 0; i < s.length; i++) {\n let p = s[i].charCodeAt() + 4\n if (p > 122) { p -= 24 }\n t += String.fromCharCode(p)\n }\n return t\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "encrypt"} -{"task_id": "JavaScript/90", "prompt": "/*\n You are given a list of integers.\n Write a function nextSmallest() that returns the 2nd smallest element of the list.\n Return null if there is no such element.\n \n nextSmallest([1, 2, 3, 4, 5]) == 2\n nextSmallest([5, 1, 4, 3, 2]) == 2\n nextSmallest([]) == null\n nextSmallest([1, 1]) == null\n */\nconst nextSmallest = (lst) => {\n", "canonical_solution": " let arr = lst\n for (let j = 0; j < arr.length; j++) {\n let ind = j\n for (let k = j + 1; k < arr.length; k++) {\n if (arr[k] < arr[ind]) {\n ind = k\n }\n }\n let tmp = arr[j]\n arr[j] = arr[ind]\n arr[ind] = tmp\n }\n let smallest = arr[0]\n let pt = 1\n while(ptsmallest){\n return arr[pt]\n }\n pt++\n }\n return null\n}\n\n", "test": "const testNextSmallest = () => {\n console.assert(nextSmallest([1, 2, 3, 4, 5]) === 2)\n console.assert(nextSmallest([5, 1, 4, 3, 2]) === 2)\n console.assert(nextSmallest([]) === null)\n console.assert(nextSmallest([1, 1]) === null)\n console.assert(nextSmallest([1, 1, 1, 1, 0]) === 1)\n console.assert(nextSmallest([1, 0 ** 0]) === null)\n console.assert(nextSmallest([-35, 34, 12, -45]) === -35)\n}\n\ntestNextSmallest()\n", "declaration": "\nconst nextSmallest = (lst) => {\n", "example_test": "const testNextSmallest = () => {\n console.assert(nextSmallest([1, 2, 3, 4, 5]) === 2)\n console.assert(nextSmallest([5, 1, 4, 3, 2]) === 2)\n console.assert(nextSmallest([]) === null)\n console.assert(nextSmallest([1, 1]) === null)\n}\ntestNextSmallest()\n", "buggy_solution": " let arr = lst\n for (let j = 0; j < arr.length; j++) {\n let ind = j\n for (let k = j + 1; k < arr.length; k++) {\n if (arr[k] < arr[ind]) {\n ind = k\n }\n }\n let tmp = arr[j]\n arr[j] = arr[ind]\n arr[ind] = tmp\n }\n let smallest = 0\n let pt = 0\n while(ptsmallest){\n return arr[pt]\n }\n pt++\n }\n return null\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "nextSmallest"} -{"task_id": "JavaScript/91", "prompt": "/*\n You'll be given a string of words, and your task is to count the number\n of boredoms. A boredom is a sentence that starts with the word \"I\".\n Sentences are delimited by '.', '?' or '!'.\n \n For example:\n >>> isBored(\"Hello world\")\n 0\n >>> isBored(\"The sky is blue. The sun is shining. I love this weather\")\n 1\n */\nconst isBored = (S) => {\n", "canonical_solution": " let t = 0\n if (S[0] == 'I' && S[1] == ' ') { t = 1 }\n for (let i = 0; i < S.length; i++) {\n if (S[i] == '.' || S[i] == '!' || S[i] == '?') {\n if (S[i + 1] == ' ' && S[i + 2] == 'I' && S[i + 3] == ' ') {\n t++\n }\n }\n }\n return t\n}\n\n", "test": "const testIsBored = () => {\n console.assert(isBored('Hello world') === 0)\n console.assert(isBored('Is the sky blue?') === 0)\n console.assert(isBored('I love It !') === 1)\n console.assert(isBored('bIt') === 0)\n console.assert(\n isBored('I feel good today. I will be productive. will kill It') === 2\n )\n console.assert(isBored('You and I are going for a walk') === 0)\n}\n\ntestIsBored()\n", "declaration": "\nconst isBored = (S) => {\n", "example_test": "const testIsBored = () => {\n console.assert(isBored('Hello world') === 0)\n console.assert(isBored('The sky is blue. The sun is shining. I love this weather') === 1)\n}\ntestIsBored()\n", "buggy_solution": " let t = 0\n if (S[0] == ' ' && S[1] == 'I') { t = 1 }\n for (let i = 0; i < S.length; i++) {\n if (S[i] == '.' || S[i] == '!' || S[i] == '?') {\n if (S[i + 1] == ' ' && S[i + 2] == 'I' && S[i + 3] == ' ') {\n t++\n }\n }\n }\n return t\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "isBored"} -{"task_id": "JavaScript/92", "prompt": "/* Create a function that takes 3 numbers.\n Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.\n Returns false in any other cases.\n Examples\n anyInt(5, 2, 7) \u279e true\n anyInt(3, 2, 2) \u279e false\n anyInt(3, -2, 1) \u279e true\n anyInt(3.6, -2.2, 2) \u279e false\n */\nconst anyInt = (x, y, z) => {\n", "canonical_solution": " if (x % 1 === 0 && y % 1 === 0 && z % 1 === 0 && (x + y === z || x + z === y || x === y + z)) {\n return true\n }\n return false\n}\n\n", "test": "const testAnyInt = () => {\n console.assert(anyInt(2, 3, 1) === true)\n console.assert(anyInt(2.5, 2, 3) === false)\n console.assert(anyInt(1.5, 5, 3.5) === false)\n console.assert(anyInt(2, 6, 2) === false)\n console.assert(anyInt(4, 2, 2) === true)\n console.assert(anyInt(2.2, 2.2, 2.2) === false)\n console.assert(anyInt(-4, 6, 2) === true)\n console.assert(anyInt(2, 1, 1) === true)\n console.assert(anyInt(3, 4, 7) === true)\n console.assert(anyInt(3.0, 4, 7) === true)\n}\n\ntestAnyInt()\n", "declaration": "\nconst anyInt = (x, y, z) => {\n", "example_test": "const testAnyInt = () => {\n console.assert(anyInt(5, 2, 7) === true)\n console.assert(anyInt(3, 2, 2) === false)\n console.assert(anyInt(3, -2, 1) === true)\n console.assert(anyInt(3.6, -2.2, 2) === false)\n}\ntestAnyInt()\n", "buggy_solution": " if (x % 1 === 0 && y % 1 === 0 && z % 1 === 0 && (x + y === z || x === y + z)) {\n return true\n }\n return false\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "anyInt"} -{"task_id": "JavaScript/93", "prompt": "/*\n Write a function that takes a message, and encodes in such a \n way that it swaps case of all letters, replaces all vowels in \n the message with the letter that appears 2 places ahead of that \n vowel in the english alphabet. \n Assume only letters. \n \n Examples:\n >>> encode('test')\n 'TGST'\n >>> encode('This is a message')\n 'tHKS KS C MGSSCGG'\n */\nconst encode = (message) => {\n", "canonical_solution": " let t = ''\n for (let i = 0; i < message.length; i++) {\n let p = message[i].charCodeAt()\n if (p > 96) { p -= 32 }\n else if (p!=32 && p < 96) { p += 32 }\n if (p == 65 || p == 97 || p == 69 || p == 101 || p == 73 || p == 105 || p == 79 || p == 111 || p == 85 || p == 117) { p += 2 }\n t += String.fromCharCode(p)\n }\n return t\n}\n\n", "test": "const testEncode = () => {\n console.assert(encode('TEST') === 'tgst')\n console.assert(encode('Mudasir') === 'mWDCSKR')\n console.assert(encode('YES') === 'ygs')\n console.assert(encode('This is a message') === 'tHKS KS C MGSSCGG')\n console.assert(\n encode('I DoNt KnOw WhAt tO WrItE') === 'k dQnT kNqW wHcT Tq wRkTg'\n )\n}\n\ntestEncode()\n", "declaration": "\nconst encode = (message) => {\n", "example_test": "const testEncode = () => {\n console.assert(encode('test') === 'TGST')\n console.assert(encode('This is a message') === 'tHKS KS C MGSSCGG')\n}\ntestEncode()\n", "buggy_solution": " let t = ''\n for (let i = 0; i < message.length; i++) {\n let p = message[i].charCodeAt()\n if (p > 96) { p -= 32 }\n else if (p!=32 && p < 96) { p += 32 }\n if (p == 65 || p == 97 || p == 69 || p == 101 || p == 73 || p == 105 || p == 79 || p == 111 || p == 85 || p == 117) { p += 2 }\n }\n return t\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "encode"} -{"task_id": "JavaScript/94", "prompt": "/*You are given a list of integers.\n You need to find the largest prime value and return the sum of its digits.\n\n Examples:\n For lst = [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3] the output should be 10\n For lst = [1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1] the output should be 25\n For lst = [1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3] the output should be 13\n For lst = [0,724,32,71,99,32,6,0,5,91,83,0,5,6] the output should be 11\n For lst = [0,81,12,3,1,21] the output should be 3\n For lst = [0,8,1,2,1,7] the output should be 7\n */\nconst skjkasdkd = (lst) => {\n", "canonical_solution": " let t = 0\n for (let i = 0; i < lst.length; i++) {\n let p = 1\n for (let j = 2; j * j <= lst[i]; j++) {\n if (lst[i] % j == 0) { p = 0; break }\n }\n if (p == 1 && lst[i] > t) { t = lst[i] }\n }\n let k = 0\n while (t != 0) {\n k += t % 10\n t = (t - t % 10) / 10\n }\n return k\n}\n\n", "test": "const testSkjkasdkd = () => {\n console.assert(\n skjkasdkd([\n 0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3,\n ]) === 10\n )\n\n console.assert(\n skjkasdkd([1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) === 25\n )\n\n console.assert(\n skjkasdkd([\n 1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3,\n ]) === 13\n )\n\n console.assert(\n skjkasdkd([0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) === 11\n )\n\n console.assert(skjkasdkd([0, 81, 12, 3, 1, 21]) === 3)\n\n console.assert(skjkasdkd([0, 8, 1, 2, 1, 7]) === 7)\n\n console.assert(skjkasdkd([8191]) === 19)\n console.assert(skjkasdkd([8191, 123456, 127, 7]) === 19)\n console.assert(skjkasdkd([127, 97, 8192]) === 10)\n}\n\ntestSkjkasdkd()\n", "declaration": "\nconst skjkasdkd = (lst) => {\n", "example_test": "const testSkjkasdkd = () => {\n console.assert(\n skjkasdkd([\n 0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3,\n ]) === 10\n )\n console.assert(\n skjkasdkd([1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) === 25\n )\n console.assert(\n skjkasdkd([\n 1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3,\n ]) === 13\n )\n console.assert(\n skjkasdkd([0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) === 11\n )\n console.assert(skjkasdkd([0, 81, 12, 3, 1, 21]) === 3)\n console.assert(skjkasdkd([0, 8, 1, 2, 1, 7]) === 7)\n}\ntestSkjkasdkd()\n", "buggy_solution": " let t = 0\n for (let i = 0; i < lst.length; i++) {\n let p = 1\n for (let j = 2; j * j <= lst[i]; j++) {\n if (lst[i] % j == 0) { p = 0; break }\n }\n if (p == 1 || lst[i] > t) { t = lst[i] }\n }\n let k = 0\n while (t != 0) {\n k += t % 10\n t = (t - t % 10) / 10\n }\n return k\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "skjkasdkd"} -{"task_id": "JavaScript/95", "prompt": "/*\n Given a dictionary, return true if all keys are strings in lower \n case or all keys are strings in upper case, else return false.\n The function should return false is the given dictionary is empty.\n Examples:\n checkDictCase({\"a\":\"apple\", \"b\":\"banana\"}) should return true.\n checkDictCase({\"a\":\"apple\", \"A\":\"banana\", \"B\":\"banana\"}) should return false.\n checkDictCase({\"a\":\"apple\", 8:\"banana\", \"a\":\"apple\"}) should return false.\n checkDictCase({\"Name\":\"John\", \"Age\":\"36\", \"City\":\"Houston\"}) should return false.\n checkDictCase({\"STATE\":\"NC\", \"ZIP\":\"12345\" }) should return true.\n */\nconst checkDictCase = (dict) => {\n", "canonical_solution": " let c = 0\n let lo = 1\n let hi = 1\n for (let key in dict) {\n c++\n for (let i = 0; i < key.length; i++) {\n if (key[i].charCodeAt() < 65 || key[i].charCodeAt() > 90) { hi = 0 }\n if (key[i].charCodeAt() < 97 || key[i].charCodeAt() > 122) { lo = 0 }\n }\n }\n if ((lo == 0 && hi == 0) || c == 0) { return false }\n return true\n}\n\n", "test": "const testCheckDictCase = () => {\n console.assert(checkDictCase({ p: 'pineapple', b: 'banana' }) === true)\n console.assert(\n checkDictCase({ p: 'pineapple', A: 'banana', B: 'banana' }) === false\n )\n console.assert(\n checkDictCase({ p: 'pineapple', 5: 'banana', a: 'apple' }) === false\n )\n console.assert(\n checkDictCase({ Name: 'John', Age: '36', City: 'Houston' }) === false\n )\n console.assert(checkDictCase({ STATE: 'NC', ZIP: '12345' }) === true)\n console.assert(checkDictCase({ fruit: 'Orange', taste: 'Sweet' }) === true)\n console.assert(checkDictCase({}) === false)\n}\n\ntestCheckDictCase()\n", "declaration": "\nconst checkDictCase = (dict) => {\n", "example_test": "const testCheckDictCase = () => {\n console.assert(checkDictCase({ p: 'pineapple', b: 'banana' }) === true)\n console.assert(\n checkDictCase({ p: 'pineapple', A: 'banana', B: 'banana' }) === false\n )\n console.assert(\n checkDictCase({ p: 'pineapple', 8: 'banana', a: 'apple' }) === false\n )\n console.assert(\n checkDictCase({ Name: 'John', Age: '36', City: 'Houston' }) === false\n )\n console.assert(checkDictCase({ STATE: 'NC', ZIP: '12345' }) === true)\n}\ntestCheckDictCase()\n", "buggy_solution": " let c = 0\n let lo = 1\n let hi = 1\n for (let key in dict) {\n c++\n for (let i = 0; i < key.length; i++) {\n if (key[i].charCodeAt() < 65 || key[i].charCodeAt() > 90) { hi = 0 }\n if (key[i].charCodeAt() < 97 || key[i].charCodeAt() > 122) { lo = 0 }\n }\n }\n if ((lo == 0 && hi == 0) && c == 0) { return false }\n return true\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "checkDictCase"} -{"task_id": "JavaScript/96", "prompt": "/*Implement a function that takes an non-negative integer and returns an array of the first n\n integers that are prime numbers and less than n.\n for example:\n countUpTo(5) => [2,3]\n countUpTo(11) => [2,3,5,7]\n countUpTo(0) => []\n countUpTo(20) => [2,3,5,7,11,13,17,19]\n countUpTo(1) => []\n countUpTo(18) => [2,3,5,7,11,13,17]\n */\nconst countUpTo = (n) => {\n", "canonical_solution": " let t = []\n for (let i = 2; i < n; i++) {\n let p = 1\n for (let j = 2; j * j <= i; j++) {\n if (i % j == 0) { p = 0; break }\n }\n if (p == 1) { t.push(i) }\n }\n return t\n}\n\n", "test": "const testCountUpTo = () => {\n console.assert(JSON.stringify(countUpTo(5)) === JSON.stringify([2, 3]))\n console.assert(JSON.stringify(countUpTo(6)) === JSON.stringify([2, 3, 5]))\n console.assert(JSON.stringify(countUpTo(7)) === JSON.stringify([2, 3, 5]))\n console.assert(JSON.stringify(countUpTo(10)) === JSON.stringify([2, 3, 5, 7]))\n console.assert(JSON.stringify(countUpTo(0)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(countUpTo(22)) ===\n JSON.stringify([2, 3, 5, 7, 11, 13, 17, 19])\n )\n console.assert(JSON.stringify(countUpTo(1)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(countUpTo(18)) === JSON.stringify([2, 3, 5, 7, 11, 13, 17])\n )\n console.assert(\n JSON.stringify(countUpTo(47)) ===\n JSON.stringify([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43])\n )\n console.assert(\n JSON.stringify(countUpTo(101)) ===\n JSON.stringify([\n 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,\n 71, 73, 79, 83, 89, 97,\n ])\n )\n}\n\ntestCountUpTo()\n", "declaration": "\nconst countUpTo = (n) => {\n", "example_test": "const testCountUpTo = () => {\n console.assert(JSON.stringify(countUpTo(5)) === JSON.stringify([2, 3]))\n console.assert(JSON.stringify(countUpTo(11)) === JSON.stringify([2, 3, 5, 7]))\n console.assert(JSON.stringify(countUpTo(0)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(countUpTo(20)) ===\n JSON.stringify([2, 3, 5, 7, 11, 13, 17, 19])\n )\n console.assert(JSON.stringify(countUpTo(1)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(countUpTo(18)) === JSON.stringify([2, 3, 5, 7, 11, 13, 17])\n )\n}\ntestCountUpTo()\n", "buggy_solution": " let t = []\n for (let i = 2; i < n; i++) {\n let p = 1\n for (let j = 2; j * j <= i; j++) {\n if (j % i == 0) { p = 0; break }\n }\n if (p == 1) { t.push(i) }\n }\n return t\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "countUpTo"} -{"task_id": "JavaScript/97", "prompt": "/*Complete the function that takes two integers and returns \n the product of their unit digits.\n Assume the input is always valid.\n Examples:\n multiply(148, 412) should return 16.\n multiply(19, 28) should return 72.\n multiply(2020, 1851) should return 0.\n multiply(14,-15) should return 20.\n */\nconst multiply = (a, b) => {\n", "canonical_solution": " if (a < 0) { a = -a }\n if (b < 0) { b = -b }\n return (a % 10) * (b % 10)\n}\n\n", "test": "const testMultiply = () => {\n console.assert(multiply(148, 412) === 16)\n console.assert(multiply(19, 28) === 72)\n console.assert(multiply(2020, 1851) === 0)\n console.assert(multiply(14, -15) === 20)\n console.assert(multiply(76, 67) === 42)\n console.assert(multiply(17, 27) === 49)\n console.assert(multiply(0, 1) === 0)\n console.assert(multiply(0, 0) === 0)\n}\n\ntestMultiply()\n", "declaration": "\nconst multiply = (a, b) => {\n", "example_test": "const testMultiply = () => {\n console.assert(multiply(148, 412) === 16)\n console.assert(multiply(19, 28) === 72)\n console.assert(multiply(2020, 1851) === 0)\n console.assert(multiply(14, -15) === 20)\n}\ntestMultiply()\n", "buggy_solution": " if (a < 0) { a = -a }\n if (b < 0) { b = -b }\n return (a % 10) * (b % 10) * a * b\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "multiply"} -{"task_id": "JavaScript/98", "prompt": "/*\n Given a string s, count the number of uppercase vowels in even indices.\n \n For example:\n countUpper('aBCdEf') returns 1\n countUpper('abcdefg') returns 0\n countUpper('dBBE') returns 0\n */\nconst countUpper = (s) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < s.length; i += 2) {\n if (s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U') { p++ }\n }\n return p\n}\n\n", "test": "const testCountUpper = () => {\n console.assert(countUpper('aBCdEf') === 1)\n console.assert(countUpper('abcdefg') === 0)\n console.assert(countUpper('dBBE') === 0)\n console.assert(countUpper('B') === 0)\n console.assert(countUpper('U') === 1)\n console.assert(countUpper('') === 0)\n console.assert(countUpper('EEEE') === 2)\n}\n\ntestCountUpper()\n", "declaration": "\nconst countUpper = (s) => {\n", "example_test": "const testCountUpper = () => {\n console.assert(countUpper('aBCdEf') === 1)\n console.assert(countUpper('abcdefg') === 0)\n console.assert(countUpper('dBBE') === 0)\n}\ntestCountUpper()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < s.length; i += 2) {\n if (s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U') { p += 2 }\n }\n return p\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "countUpper"} -{"task_id": "JavaScript/99", "prompt": "/* Create a function that takes a value (string) representing a number\n and returns the closest integer to it. If the number is equidistant\n from two integers, round it away from zero.\n Examples\n >>> closestInteger(\"10\")\n 10\n >>> closestInteger(\"15.3\")\n 15\n Note:\n Rounding away from zero means that if the given number is equidistant\n from two integers, the one you should return is the one that is the\n farthest from zero. For example closestInteger(\"14.5\") should\n return 15 and closestInteger(\"-14.5\") should return -15.\n */\nconst closestInteger = (value) => {\n", "canonical_solution": " value = Number(value)\n let t = value % 1\n if (t < 0.5 && t > -0.5) { value -= t }\n else { value += t }\n return value\n}\n\n", "test": "const testClosestInteger = () => {\n console.assert(closestInteger('10') === 10)\n console.assert(closestInteger('14.5') === 15)\n console.assert(closestInteger('-15.5') === -16)\n console.assert(closestInteger('15.3') === 15)\n console.assert(closestInteger('0') === 0)\n}\n\ntestClosestInteger()\n", "declaration": "\nconst closestInteger = (value) => {\n", "example_test": "const testClosestInteger = () => {\n console.assert(closestInteger('10') === 10)\n console.assert(closestInteger('15.3') === 15)\n}\ntestClosestInteger()\n", "buggy_solution": " value = Number(value)\n let t = value % 1\n if (t < 0.5 && t > -0.5) { value += t }\n else { value -= t }\n return value\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "closestInteger"} -{"task_id": "JavaScript/100", "prompt": "/*\n Given a positive integer n, you have to make a pile of n levels of stones.\n The first level has n stones.\n The number of stones in the next level is:\n - the next odd number if n is odd.\n - the next even number if n is even.\n Return the number of stones in each level in a list, where element at index\n i represents the number of stones in the level (i+1).\n\n Examples:\n >>> makeAPile(3)\n [3, 5, 7]\n */\nconst makeAPile = (n) => {\n", "canonical_solution": " let t = []\n for (let i = n; i < n * 3; i += 2) {\n t.push(i)\n }\n return t\n}\n\n", "test": "const testMakeAPile = () => {\n console.assert(JSON.stringify(makeAPile(3)) === JSON.stringify([3, 5, 7]))\n console.assert(JSON.stringify(makeAPile(4)) === JSON.stringify([4, 6, 8, 10]))\n console.assert(\n JSON.stringify(makeAPile(5)) === JSON.stringify([5, 7, 9, 11, 13])\n )\n console.assert(\n JSON.stringify(makeAPile(6)) === JSON.stringify([6, 8, 10, 12, 14, 16])\n )\n console.assert(\n JSON.stringify(makeAPile(8)) ===\n JSON.stringify([8, 10, 12, 14, 16, 18, 20, 22])\n )\n}\n\ntestMakeAPile()\n", "declaration": "\nconst makeAPile = (n) => {\n", "example_test": "const testMakeAPile = () => {\n console.assert(JSON.stringify(makeAPile(3)) === JSON.stringify([3, 5, 7]))\n}\ntestMakeAPile()\n", "buggy_solution": " let t = []\n for (let i = n; i < n * 3; i += 2) {\n t.push(i)\n t.push(n)\n }\n return t\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "makeAPile"} -{"task_id": "JavaScript/101", "prompt": "/*\n You will be given a string of words separated by commas or spaces. Your task is\n to split the string into words and return an array of the words.\n \n For example:\n wordsString(\"Hi, my name is John\") == [\"Hi\", \"my\", \"name\", \"is\", \"John\"]\n wordsString(\"One, two, three, four, five, six\") == [\"One\", \"two\", \"three\", \"four\", \"five\", \"six\"]\n */\nconst wordsString = (s) => {\n", "canonical_solution": " let t = ''\n let p = []\n let k = 0\n for (let i = 0; i < s.length; i++) {\n if (s[i] == ' ' || s[i] == ',') {\n if (k == 0) {\n k = 1;\n p.push(t);\n t = '';\n }\n }\n else {\n k = 0;\n t += s[i]\n }\n }\n if (t != '') {\n p.push(t);\n }\n return p\n}\n\n", "test": "const testWordsString = () => {\n console.assert(\n JSON.stringify(wordsString('Hi, my name is John')) ===\n JSON.stringify(['Hi', 'my', 'name', 'is', 'John'])\n )\n console.assert(\n JSON.stringify(wordsString('One, two, three, four, five, six')) ===\n JSON.stringify(['One', 'two', 'three', 'four', 'five', 'six'])\n )\n console.assert(\n JSON.stringify(wordsString('Hi, my name')) ===\n JSON.stringify(['Hi', 'my', 'name'])\n )\n console.assert(\n JSON.stringify(wordsString('One,, two, three, four, five, six,')) ===\n JSON.stringify(['One', 'two', 'three', 'four', 'five', 'six'])\n )\n console.assert(JSON.stringify(wordsString('')) === JSON.stringify([]))\n console.assert(\n JSON.stringify(wordsString('ahmed , gamal')) ===\n JSON.stringify(['ahmed', 'gamal'])\n )\n}\n\ntestWordsString()\n", "declaration": "\nconst wordsString = (s) => {\n", "example_test": "const testWordsString = () => {\n console.assert(\n JSON.stringify(wordsString('Hi, my name is John')) ===\n JSON.stringify(['Hi', 'my', 'name', 'is', 'John'])\n )\n console.assert(\n JSON.stringify(wordsString('One, two, three, four, five, six')) ===\n JSON.stringify(['One', 'two', 'three', 'four', 'five', 'six'])\n )\n}\ntestWordsString()\n", "buggy_solution": " let t = ','\n let p = []\n let k = 0\n for (let i = 0; i < s.length; i++) {\n if (s[i] == ' ' || s[i] == ',') {\n if (k == 0) {\n k = 1;\n p.push(t);\n t = ',';\n }\n }\n else {\n k = 0;\n t += s[i]\n }\n }\n if (t != '') {\n p.push(t);\n }\n return p\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "wordsString"} -{"task_id": "JavaScript/102", "prompt": "/*This function takes two positive numbers x and y and returns the\n biggest even integer number that is in the range [x, y] inclusive. If \n there's no such number, then the function should return -1.\n\n For example:\n chooseNum(12, 15) = 14\n chooseNum(13, 12) = -1\n */\nconst chooseNum = (x, y) => {\n", "canonical_solution": " for (let i = y; i >= x; i--) {\n if (i % 2 == 0) {return i }\n }\n return -1\n}\n\n", "test": "const testChooseNum = () => {\n console.assert(chooseNum(12, 15) === 14)\n console.assert(chooseNum(13, 12) === -1)\n console.assert(chooseNum(33, 12354) === 12354)\n console.assert(chooseNum(5234, 5233) === -1)\n console.assert(chooseNum(6, 29) === 28)\n console.assert(chooseNum(27, 10) === -1)\n console.assert(chooseNum(7, 7) === -1)\n console.assert(chooseNum(546, 546) === 546)\n}\n\ntestChooseNum()\n", "declaration": "\nconst chooseNum = (x, y) => {\n", "example_test": "const testChooseNum = () => {\n console.assert(chooseNum(12, 15) === 14)\n console.assert(chooseNum(13, 12) === -1)\n}\ntestChooseNum()\n", "buggy_solution": " for (let i = y; i >= x; i--) {\n if (i % 2 == 0) {return i }\n }\n return x\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "chooseNum"} -{"task_id": "JavaScript/103", "prompt": "/*You are given two positive integers n and m, and your task is to compute the\n average of the integers from n through m (including n and m). \n Round the answer to the nearest integer and convert that to binary.\n If n is greater than m, return -1.\n Example:\n roundedAvg(1, 5) => \"0b11\"\n roundedAvg(7, 5) => -1\n roundedAvg(10, 20) => \"0b1111\"\n roundedAvg(20, 33) => \"0b11010\"\n */\nconst roundedAvg = (n, m) => {\n", "canonical_solution": " if (n > m) { return -1 }\n let k = (n + m) / 2\n if (k % 1 != 0) { k = (n + m + 1) / 2 }\n return '0b' + k.toString(2)\n}\n\n", "test": "const testRoundedAvg = () => {\n console.assert(roundedAvg(1, 5) === '0b11')\n console.assert(roundedAvg(7, 13) === '0b1010')\n console.assert(roundedAvg(964, 977) === '0b1111001011')\n console.assert(roundedAvg(996, 997) === '0b1111100101')\n console.assert(roundedAvg(560, 851) === '0b1011000010')\n console.assert(roundedAvg(185, 546) === '0b101101110')\n console.assert(roundedAvg(362, 496) === '0b110101101')\n console.assert(roundedAvg(350, 902) === '0b1001110010')\n console.assert(roundedAvg(197, 233) === '0b11010111')\n console.assert(roundedAvg(7, 5) === -1)\n console.assert(roundedAvg(5, 1) === -1)\n console.assert(roundedAvg(5, 5) === '0b101')\n}\n\ntestRoundedAvg()\n", "declaration": "\nconst roundedAvg = (n, m) => {\n", "example_test": "const testRoundedAvg = () => {\n console.assert(roundedAvg(1, 5) === '0b11')\n console.assert(roundedAvg(7, 13) === '0b1010')\n console.assert(roundedAvg(7, 5) === -1)\n console.assert(roundedAvg(10,20) === \"0b1111\")\n console.assert(roundedAvg(20,33) === '0b11011')\n}\ntestRoundedAvg()\n", "buggy_solution": " if (n > m) { return -1 }\n let k = (n + m) / 2\n if (k % 1 != 0) { k = (n + m) / 2 }\n return '0b' + k.toString(2)\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "roundedAvg"} -{"task_id": "JavaScript/104", "prompt": "/*Given a list of positive integers x. return a sorted list of all \n elements that hasn't any even digit.\n\n Note: Returned list should be sorted in increasing order.\n \n For example:\n >>> uniqueDigits([15, 33, 1422, 1])\n [1, 15, 33]\n >>> uniqueDigits([152, 323, 1422, 10])\n []\n */\nconst uniqueDigits = (x) => {\n", "canonical_solution": " let p = []\n for (let i = 0; i < x.length; i++) {\n let h = x[i]\n let boo = 1\n while (h > 0) {\n let r = h % 10\n if (r % 2 == 0) {\n boo = 0;\n break;\n }\n h = (h - r) / 10\n }\n if (boo) {\n p.push(x[i])\n }\n }\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "test": "const testUniqueDigits = () => {\n console.assert(\n JSON.stringify(uniqueDigits([15, 33, 1422, 1])) ===\n JSON.stringify([1, 15, 33])\n )\n console.assert(\n JSON.stringify(uniqueDigits([152, 323, 1422, 10])) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(uniqueDigits([12345, 2033, 111, 151])) ===\n JSON.stringify([111, 151])\n )\n console.assert(\n JSON.stringify(uniqueDigits([135, 103, 31])) === JSON.stringify([31, 135])\n )\n}\n\ntestUniqueDigits()\n", "declaration": "\nconst uniqueDigits = (x) => {\n", "example_test": "const testUniqueDigits = () => {\n console.assert(\n JSON.stringify(uniqueDigits([15, 33, 1422, 1])) ===\n JSON.stringify([1, 15, 33])\n )\n console.assert(\n JSON.stringify(uniqueDigits([152, 323, 1422, 10])) === JSON.stringify([])\n )\n}\ntestUniqueDigits()\n", "buggy_solution": " let p = []\n for (let i = 0; i < x.length; i++) {\n let h = x[i]\n let boo = 1\n while (h > 0) {\n let r = h % 10\n if (r % 2 == 0) {\n boo = 0;\n break;\n }\n h = (h - r) / 10\n }\n if (boo) {\n p.push(x[i]);\n p.push(h);\n }\n }\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "uniqueDigits"} -{"task_id": "JavaScript/105", "prompt": "/*\n Given an array of integers, sort the integers that are between 1 and 9 inclusive,\n reverse the resulting array, and then replace each digit by its corresponding name from\n \"One\", \"Two\", \"Three\", \"Four\", \"Five\", \"Six\", \"Seven\", \"Eight\", \"Nine\".\n\n For example:\n arr = [2, 1, 1, 4, 5, 8, 2, 3] \n -> sort arr -> [1, 1, 2, 2, 3, 4, 5, 8] \n -> reverse arr -> [8, 5, 4, 3, 2, 2, 1, 1]\n return [\"Eight\", \"Five\", \"Four\", \"Three\", \"Two\", \"Two\", \"One\", \"One\"]\n \n If the array is empty, return an empty array:\n arr = []\n return []\n \n If the array has any strange number ignore it:\n arr = [1, -1 , 55] \n -> sort arr -> [-1, 1, 55]\n -> reverse arr -> [55, 1, -1]\n return = ['One']\n */\nconst byLength = (arr) => {\n", "canonical_solution": " p = []\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] > 0 && arr[i] < 10) { p.push(arr[i]) }\n }\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] > p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n let l = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine']\n let t = []\n for (let j = 0; j < p.length; j++) {\n t.push(l[p[j]-1])\n }\n return t\n}\n\n", "test": "const testByLength = () => {\n console.assert(\n JSON.stringify(byLength([2, 1, 1, 4, 5, 8, 2, 3])) ===\n JSON.stringify([\n 'Eight',\n 'Five',\n 'Four',\n 'Three',\n 'Two',\n 'Two',\n 'One',\n 'One',\n ])\n )\n console.assert(JSON.stringify(byLength([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(byLength([1, -1, 55])) === JSON.stringify(['One'])\n )\n console.assert(\n JSON.stringify(byLength([1, -1, 3, 2])) ===\n JSON.stringify(['Three', 'Two', 'One'])\n )\n console.assert(\n JSON.stringify(byLength([9, 4, 8])) ===\n JSON.stringify(['Nine', 'Eight', 'Four'])\n )\n}\n\ntestByLength()\n", "declaration": "\nconst byLength = (arr) => {\n", "example_test": "const testByLength = () => {\n console.assert(\n JSON.stringify(byLength([2, 1, 1, 4, 5, 8, 2, 3])) ===\n JSON.stringify([\n 'Eight',\n 'Five',\n 'Four',\n 'Three',\n 'Two',\n 'Two',\n 'One',\n 'One',\n ])\n )\n console.assert(JSON.stringify(byLength([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(byLength([1, -1, 55])) === JSON.stringify(['One'])\n )\n}\ntestByLength()\n", "buggy_solution": " p = []\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] > 0 && arr[i] < 10) { p.push(arr[i]) }\n }\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] > p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[ind] = tmp\n }\n }\n let l = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine']\n let t = []\n for (let j = 0; j < p.length; j++) {\n t.push(l[p[j]-1])\n }\n return t\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "byLength"} -{"task_id": "JavaScript/106", "prompt": "/* Implement the function f that takes n as a parameter,\n and returns a list of size n, such that the value of the element at index i is the factorial of i if i is even\n or the sum of numbers from 1 to i otherwise.\n i starts from 1.\n the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).\n Example:\n f(5) == [1, 2, 6, 24, 15]\n */\nconst f = (n) => {\n", "canonical_solution": " let f = 1\n let p = 0\n let k = []\n for (let i = 1; i <= n; i++) {\n p += i;\n f *= i;\n if (i % 2 == 0) { k.push(f) }\n else { k.push(p) }\n }\n return k\n}\n\n", "test": "const testF = () => {\n console.assert(JSON.stringify(f(5)) === JSON.stringify([1, 2, 6, 24, 15]))\n console.assert(\n JSON.stringify(f(7)) === JSON.stringify([1, 2, 6, 24, 15, 720, 28])\n )\n console.assert(JSON.stringify(f(1)) === JSON.stringify([1]))\n console.assert(JSON.stringify(f(3)) === JSON.stringify([1, 2, 6]))\n}\n\ntestF()\n", "declaration": "\nconst f = (n) => {\n", "example_test": "const testF = () => {\n console.assert(JSON.stringify(f(5)) === JSON.stringify([1, 2, 6, 24, 15]))\n}\ntestF()\n", "buggy_solution": " let f = 1\n let p = 0\n let k = []\n for (let i = 1; i <= n; i++) {\n p += i;\n f *= i;\n if (f % 2 == 0) { k.push(f) }\n else { k.push(p) }\n }\n return k\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "f"} -{"task_id": "JavaScript/107", "prompt": "/*\n Given a positive integer n, return a tuple that has the number of even and odd\n integer palindromes that fall within the range(1, n), inclusive.\n\n Example 1:\n\n Input: 3\n Output: (1, 2)\n Explanation:\n Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.\n\n Example 2:\n\n Input: 12\n Output: (4, 6)\n Explanation:\n Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.\n\n Note:\n 1. 1 <= n <= 10^3\n 2. returned tuple has the number of even and odd integer palindromes respectively.\n */\nconst evenOddPalindrome = (n) => {\n", "canonical_solution": " let e = 0\n let o = 0\n for (let i = 1; i <= n; i++) {\n let k = i.toString()\n let p = 1\n for (let j = 0; j < k.length; j++) {\n if (k[j] != k[k.length - j - 1]) {\n p = 0;\n break;\n }\n }\n if (p == 1) {\n if (k % 2 == 0) { e++ }\n else { o++ }\n }\n }\n return (e, o)\n}\n\n", "test": "const testEvenOddPalindrome = () => {\n console.assert(\n JSON.stringify(evenOddPalindrome(123)) === JSON.stringify((8, 13))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(12)) === JSON.stringify((4, 6))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(3)) === JSON.stringify((1, 2))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(63)) === JSON.stringify((6, 8))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(25)) === JSON.stringify((5, 6))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(19)) === JSON.stringify((4, 6))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(9)) === JSON.stringify((4, 5))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(1)) === JSON.stringify((0, 1))\n )\n}\n\ntestEvenOddPalindrome()\n", "declaration": "\nconst evenOddPalindrome = (n) => {\n", "example_test": "const testEvenOddPalindrome = () => {\n console.assert(\n JSON.stringify(evenOddPalindrome(12)) === JSON.stringify((4, 6))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(3)) === JSON.stringify((1, 2))\n )\n}\ntestEvenOddPalindrome()\n", "buggy_solution": " let e = 0\n let o = 0\n for (let i = 1; i <= n; i++) {\n let k = i.toString()\n let p = 1\n for (let j = 0; j < k.length; j++) {\n if (k[j] != k[k.length - j - 1]) {\n p = 0;\n break;\n }\n }\n if (p == 1) {\n if (k % 2 == 1) { e++ }\n else { o++ }\n }\n }\n return (e, o)\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "evenOddPalindrome"} -{"task_id": "JavaScript/108", "prompt": "/*\n Write a function countNums which takes an array of integers and returns\n the number of elements which has a sum of digits > 0.\n If a number is negative, then its first signed digit will be negative:\n e.g. -123 has signed digits -1, 2, and 3.\n >>> countNums([]) == 0\n >>> countNums([-1, 11, -11]) == 1\n >>> countNums([1, 1, 2]) == 3\n */\nconst countNums = (arr) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < arr.length; i++) {\n let h = arr[i]\n if (h > 0) {\n p++;\n continue;\n }\n let k = 0\n h = -h\n while (h >= 10) {\n k += h % 10;\n h = (h - h % 10) / 10;\n }\n k -= h;\n if (k > 0) { p++ }\n }\n return p\n}\n\n", "test": "const testCountNums = () => {\n console.assert(countNums([]) === 0)\n console.assert(countNums([-1, -2, 0]) === 0)\n console.assert(countNums([1, 1, 2, -2, 3, 4, 5]) === 6)\n console.assert(countNums([1, 6, 9, -6, 0, 1, 5]) === 5)\n console.assert(countNums([1, 100, 98, -7, 1, -1]) === 4)\n console.assert(countNums([12, 23, 34, -45, -56, 0]) === 5)\n console.assert(countNums([-0, 1 ** 0]) === 1)\n console.assert(countNums([1]) === 1)\n}\n\ntestCountNums()\n", "declaration": "\nconst countNums = (arr) => {\n", "example_test": "const testCountNums = () => {\n console.assert(countNums([]) === 0)\n console.assert(countNums([-1, 11, -11]) === 1)\n console.assert(countNums([1, 1, 2]) === 3)\n}\ntestCountNums()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < arr.length; i++) {\n let h = arr[i]\n if (h > 0) {\n p++;\n continue;\n }\n let k = 0\n h = -h\n while (h >= 10) {\n k += h % 10 * -1;\n h = (h - h % 10) / 10;\n }\n k -= h;\n if (k > 0) { p++ }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "countNums"} -{"task_id": "JavaScript/109", "prompt": "/*We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The\n numbers in the array will be randomly ordered. Your task is to determine if\n it is possible to get an array sorted in non-decreasing order by performing \n the following operation on the given array:\n You are allowed to perform right shift operation any number of times.\n \n One right shift operation means shifting all elements of the array by one\n position in the right direction. The last element of the array will be moved to\n the starting position in the array i.e. 0th index. \n\n If it is possible to obtain the sorted array by performing the above operation\n then return true else return false.\n If the given array is empty then return true.\n\n Note: The given list is guaranteed to have unique elements.\n\n For Example:\n \n moveOneBall([3, 4, 5, 1, 2])==>true\n Explanation: By performin 2 right shift operations, non-decreasing order can\n be achieved for the given array.\n moveOneBall([3, 5, 4, 1, 2])==>false\n Explanation:It is not possible to get non-decreasing order for the given\n array by performing any number of right shift operations.\n \n */\nconst moveOneBall = (arr) => {\n", "canonical_solution": " if (arr.length == 0) { return true }\n let k = 0\n let len = arr.length\n for (let i = 0; i < len; i++) {\n let t = 1;\n for (let j = 1; j < len; j++) {\n if (arr[j] < arr[j - 1]) {\n t = 0;\n break;\n }\n }\n if (t == 1) {\n k = 1;\n break;\n }\n arr.push(arr[0]);\n arr.shift()\n }\n if (k == 1) { return true }\n return false\n}\n\n", "test": "const testMoveOneBall = () => {\n console.assert(moveOneBall([3, 4, 5, 1, 2]) === true)\n console.assert(moveOneBall([3, 5, 10, 1, 2]) === true)\n console.assert(moveOneBall([4, 3, 1, 2]) === false)\n console.assert(moveOneBall([3, 5, 4, 1, 2]) === false)\n console.assert(moveOneBall([]) === true)\n}\n\ntestMoveOneBall()\n", "declaration": "\nconst moveOneBall = (arr) => {\n", "example_test": "const testMoveOneBall = () => {\n console.assert(moveOneBall([3, 4, 5, 1, 2]) === true)\n console.assert(moveOneBall([3, 5, 4, 1, 2]) === false)\n}\ntestMoveOneBall()\n", "buggy_solution": " if (arr.length == 0) { return true }\n let k = 0\n let len = arr.length\n for (let i = 0; i < len; i++) {\n let t = 1;\n for (let j = 1; j < len; j++) {\n if (arr[j] < arr[j - 1]) {\n t = 0;\n break;\n }\n }\n if (t == 1) {\n k = 1;\n break;\n }\n arr.push(arr[j]);\n arr.shift()\n }\n if (k == 1) { return true }\n return false\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "moveOneBall"} -{"task_id": "JavaScript/110", "prompt": "/*In this problem, you will implement a function that takes two lists of numbers,\n and determines whether it is possible to perform an exchange of elements\n between them to make lst1 a list of only even numbers.\n There is no limit on the number of exchanged elements between lst1 and lst2.\n If it is possible to exchange elements between the lst1 and lst2 to make\n all the elements of lst1 to be even, return \"YES\".\n Otherwise, return \"NO\".\n For example:\n exchange([1, 2, 3, 4], [1, 2, 3, 4]) => \"YES\"\n exchange([1, 2, 3, 4], [1, 5, 3, 4]) => \"NO\"\n It is assumed that the input lists will be non-empty.\n */\nconst exchange = (lst1, lst2) => {\n", "canonical_solution": " let k = lst1.length\n let t = 0\n for (let i = 0; i < lst1.length; i++) {\n if (lst1[i] % 2 == 0) { t++ }\n }\n for (let i = 0; i < lst2.length; i++) {\n if (lst2[i] % 2 == 0) { t++ }\n }\n if (t >= k) { return 'YES' }\n return 'NO'\n}\n\n", "test": "const testExchange = () => {\n console.assert(exchange([1, 2, 3, 4], [1, 2, 3, 4]) === 'YES')\n console.assert(exchange([1, 2, 3, 4], [1, 5, 3, 4]) === 'NO')\n console.assert(exchange([1, 2, 3, 4], [2, 1, 4, 3]) === 'YES')\n console.assert(exchange([5, 7, 3], [2, 6, 4]) === 'YES')\n console.assert(exchange([5, 7, 3], [2, 6, 3]) === 'NO')\n console.assert(exchange([3, 2, 6, 1, 8, 9], [3, 5, 5, 1, 1, 1]) === 'NO')\n console.assert(exchange([100, 200], [200, 200]) === 'YES')\n}\n\ntestExchange()\n", "declaration": "\nconst exchange = (lst1, lst2) => {\n", "example_test": "const testExchange = () => {\n console.assert(exchange([1, 2, 3, 4], [1, 2, 3, 4]) === 'YES')\n console.assert(exchange([1, 2, 3, 4], [1, 5, 3, 4]) === 'NO')\n}\ntestExchange()\n", "buggy_solution": " let k = lst1.length\n let t = 0\n for (let i = 0; i < lst1.length; i++) {\n if (lst1[i] % 2 == 0) { t++ }\n }\n for (let i = 0; i < lst2.length; i++) {\n if (lst2[i] % 2 == 0) { t++ }\n }\n if (k >= t) { return 'YES' }\n return 'NO'\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "exchange"} -{"task_id": "JavaScript/111", "prompt": "/*Given a string representing a space separated lowercase letters, return a dictionary\n of the letter with the most repetition and containing the corresponding count.\n If several letters have the same occurrence, return all of them.\n \n Example:\n histogram('a b c') == {'a': 1, 'b': 1, 'c': 1}\n histogram('a b b a') == {'a': 2, 'b': 2}\n histogram('a b c a b') == {'a': 2, 'b': 2}\n histogram('b b b b a') == {'b': 4}\n histogram('') == {}\n\n */\nconst histogram = (test) => {\n", "canonical_solution": " let d = {}\n let t = test.split(/\\s/)\n if (test == '') { t = [] }\n for (m in t) {\n if (t[m] in d) {\n d[t[m]]++\n }\n else {\n d[t[m]] = 1\n }\n }\n s = Object.keys(d).sort(function (a, b) { return - d[a] + d[b]; });\n if (s.length == 0) { return {} }\n let g = d[s[0]]\n let l = {}\n for (let ss=0; ss {\n console.assert(\n JSON.stringify(histogram('a b b a')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c a b')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c d g')) ===\n JSON.stringify({ a: 1, b: 1, c: 1, d: 1, g: 1 })\n )\n console.assert(\n JSON.stringify(histogram('r t g')) === JSON.stringify({ r: 1, t: 1, g: 1 })\n )\n console.assert(\n JSON.stringify(histogram('b b b b a')) === JSON.stringify({ b: 4 })\n )\n console.assert(\n JSON.stringify(histogram('r t g')) === JSON.stringify({ r: 1, t: 1, g: 1 })\n )\n console.assert(JSON.stringify(histogram('')) === JSON.stringify({}))\n console.assert(JSON.stringify(histogram('a')) === JSON.stringify({ a: 1 }))\n}\n\ntestHistogram()\n", "declaration": "\nconst histogram = (test) => {\n", "example_test": "const testHistogram = () => {\n console.assert(\n JSON.stringify(histogram('a b b a')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c a b')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c d g')) ===\n JSON.stringify({ a: 1, b: 1, c: 1, d: 1, g: 1 })\n )\n console.assert(\n JSON.stringify(histogram('a b c')) === JSON.stringify({ a: 1, b: 1, c: 1 })\n )\n console.assert(\n JSON.stringify(histogram('b b b b a')) === JSON.stringify({ b: 4 })\n )\n console.assert(JSON.stringify(histogram('')) === JSON.stringify({}))\n}\ntestHistogram()\n", "buggy_solution": " let d = {}\n let t = test.split(/\\s/)\n if (test == '') { t = [] }\n for (m in t) {\n if (t[m] in d) {\n d[t[m]]++\n }\n else {\n d[t[m]] = 1\n }\n }\n s = Object.keys(d).sort(function (a, b) { return - d[a] + d[b]; });\n if (s.length == 0) { return {} }\n let g = d[s[0]]\n let l = {}\n for (let ss=1; ss {\n", "canonical_solution": " let t = ''\n for (let i = 0; i < s.length; i++) {\n let y = 1\n for (let j = 0; j < c.length; j++) {\n if (s[i] == c[j]) {\n y = 0\n }\n }\n if (y == 1) {\n t += s[i]\n }\n }\n let isPalindrome = true\n for (let i = 0; i < Math.floor(t.length / 2); i++) {\n if (t[i] != t[t.length - i - 1]) {\n isPalindrome = false\n break\n }\n }\n return [t, isPalindrome];\n}\n\n", "test": "const testReverseDelete = () => {\n console.assert(JSON.stringify(reverseDelete('abcde', 'ae')) ===\n JSON.stringify(['bcd', false]))\n console.assert(JSON.stringify(reverseDelete('abcdef', 'b')) ===\n JSON.stringify(['acdef', false]))\n console.assert(JSON.stringify(reverseDelete('abcdedcba', 'ab')) ===\n JSON.stringify(['cdedc', true]))\n console.assert(JSON.stringify(reverseDelete('dwik', 'w')) ===\n JSON.stringify(['dik', false]))\n console.assert(JSON.stringify(reverseDelete('a', 'a')) ===\n JSON.stringify(['', true]))\n console.assert(JSON.stringify(reverseDelete('abcdedcba', '')) ===\n JSON.stringify(['abcdedcba', true]))\n console.assert(JSON.stringify(reverseDelete('abcdedcba', 'v')) ===\n JSON.stringify(['abcdedcba', true]))\n console.assert(JSON.stringify(reverseDelete('vabba', 'v')) ===\n JSON.stringify(['abba', true]))\n console.assert(JSON.stringify(reverseDelete('mamma', 'mia')) ===\n JSON.stringify(['', true]))\n}\n\ntestReverseDelete()\n", "declaration": "\nconst reverseDelete = (s, c) => {\n", "example_test": "const testReverseDelete = () => {\n console.assert(JSON.stringify(reverseDelete('abcde', 'ae'))) ===\n JSON.stringify(['bcd', false])\n console.assert(JSON.stringify(reverseDelete('abcdef', 'b'))) ===\n JSON.stringify(['acdef', false])\n console.assert(JSON.stringify(reverseDelete('abcdedcba', 'ab'))) ===\n JSON.stringify(['cdedc', true])\n}\ntestReverseDelete()\n", "buggy_solution": " let t = ''\n for (let i = 0; i < s.length; i++) {\n let y = 1\n for (let j = 0; j < c.length; j++) {\n if (s[i] == c[j]) {\n y = 0\n }\n }\n if (y == 1) {\n t += s[i]\n }\n }\n let isPalindrome = false\n for (let i = 0; i < Math.floor(t.length / 2); i++) {\n if (t[i] != t[t.length - i - 1]) {\n isPalindrome = true\n break\n }\n }\n return [t, isPalindrome];\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "reverseDelete"} -{"task_id": "JavaScript/113", "prompt": "/*Given a list of strings, where each string consists of only digits, return a list.\n Each element i of the output should be \"the number of odd elements in the\n string i of the input.\" where all the i's should be replaced by the number\n of odd digits in the i'th string of the input.\n\n >>> oddCount(['1234567'])\n [\"the number of odd elements 4n the str4ng 4 of the 4nput.\"]\n >>> oddCount(['3',\"11111111\"])\n [\"the number of odd elements 1n the str1ng 1 of the 1nput.\",\n \"the number of odd elements 8n the str8ng 8 of the 8nput.\"]\n */\nconst oddCount = (lst) => {\n", "canonical_solution": " let d = []\n for (let i = 0; i < lst.length; i++) {\n let p = 0;\n let h = lst[i].length\n for (let j = 0; j < h; j++) {\n if (lst[i][j].charCodeAt() % 2 == 1) { p++ }\n }\n p = p.toString()\n d.push('the number of odd elements ' + p + 'n the str' + p + 'ng ' + p + ' of the ' + p + 'nput.')\n }\n return d\n}\n\n", "test": "const testOddCount = () => {\n console.assert(\n JSON.stringify(oddCount(['1234567'])) ===\n JSON.stringify([\n 'the number of odd elements 4n the str4ng 4 of the 4nput.',\n ])\n )\n console.assert(JSON.stringify(\n oddCount(['3', '11111111'])) ===\n JSON.stringify([\n 'the number of odd elements 1n the str1ng 1 of the 1nput.',\n 'the number of odd elements 8n the str8ng 8 of the 8nput.',\n ])\n )\n console.assert(\n JSON.stringify(oddCount(['271', '137', '314'])) ===\n JSON.stringify([\n 'the number of odd elements 2n the str2ng 2 of the 2nput.',\n 'the number of odd elements 3n the str3ng 3 of the 3nput.',\n 'the number of odd elements 2n the str2ng 2 of the 2nput.',\n ])\n )\n}\n\ntestOddCount()\n", "declaration": "\nconst oddCount = (lst) => {\n", "example_test": "const testOddCount = () => {\n console.assert(\n JSON.stringify(oddCount(['1234567'])) ===\n JSON.stringify([\n 'the number of odd elements 4n the str4ng 4 of the 4nput.',\n ])\n )\n console.assert(JSON.stringify(\n oddCount(['3', '11111111'])) ===\n JSON.stringify([\n 'the number of odd elements 1n the str1ng 1 of the 1nput.',\n 'the number of odd elements 8n the str8ng 8 of the 8nput.',\n ])\n )\n}\ntestOddCount()\n", "buggy_solution": " let d = []\n for (let i = 0; i < lst.length; i++) {\n let p = 0;\n let h = lst[i].length\n for (let j = 0; j < h; j++) {\n if (lst[i][j].charCodeAt() % 2 == 1) { p++ }\n }\n p = p.toString()\n d.push('the number of odd elements ' + p + 'n the str' + p + 'ng ' + p + ' of ' p + ' the ' + p + 'nput.')\n }\n return d\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "oddCount"} -{"task_id": "JavaScript/114", "prompt": "/*\n Given an array of integers nums, find the minimum sum of any non-empty sub-array\n of nums.\n Example\n minSubArraySum([2, 3, 4, 1, 2, 4]) == 1\n minSubArraySum([-1, -2, -3]) == -6\n */\nconst minSubArraySum = (nums) => {\n", "canonical_solution": " let min = nums[0]\n for (let i = 0; i < nums.length; i++) {\n for (let j = i + 1; j <= nums.length; j++) {\n let s = 0;\n for (let k = i; k < j; k++) {\n s += nums[k]\n }\n if (s < min) { min = s }\n }\n }\n return min\n}\n\n", "test": "const testMinSubArraySum = () => {\n console.assert(minSubArraySum([2, 3, 4, 1, 2, 4]) === 1)\n console.assert(minSubArraySum([-1, -2, -3]) === -6)\n console.assert(minSubArraySum([-1, -2, -3, 2, -10]) === -14)\n console.assert(minSubArraySum([-9999999999999999]) === -9999999999999999)\n console.assert(minSubArraySum([0, 10, 20, 1000000]) === 0)\n console.assert(minSubArraySum([-1, -2, -3, 10, -5]) === -6)\n console.assert(minSubArraySum([100, -1, -2, -3, 10, -5]) === -6)\n console.assert(minSubArraySum([10, 11, 13, 8, 3, 4]) === 3)\n console.assert(minSubArraySum([100, -33, 32, -1, 0, -2]) === -33)\n console.assert(minSubArraySum([-10]) === -10)\n console.assert(minSubArraySum([7]) === 7)\n console.assert(minSubArraySum([1, -1]) === -1)\n}\n\ntestMinSubArraySum()\n", "declaration": "\nconst minSubArraySum = (nums) => {\n", "example_test": "const testMinSubArraySum = () => {\n console.assert(minSubArraySum([2, 3, 4, 1, 2, 4]) === 1)\n console.assert(minSubArraySum([-1, -2, -3]) === -6)\n}\ntestMinSubArraySum()\n", "buggy_solution": " let min = Math.min(nums)\n for (let i = 0; i < nums.length; i++) {\n for (let j = i + 1; j <= nums.length; j++) {\n let s = 0;\n for (let k = i; k < j; k++) {\n s += nums[k]\n }\n if (s < min) { min = s }\n }\n }\n return min\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "minSubarraySum"} -{"task_id": "JavaScript/115", "prompt": "/*\n You are given a rectangular grid of wells. Each row represents a single well,\n and each 1 in a row represents a single unit of water.\n Each well has a corresponding bucket that can be used to extract water from it, \n and all buckets have the same capacity.\n Your task is to use the buckets to empty the wells.\n Output the number of times you need to lower the buckets.\n\n Example 1:\n Input: \n grid : [[0,0,1,0], [0,1,0,0], [1,1,1,1]]\n bucket_capacity : 1\n Output: 6\n\n Example 2:\n Input: \n grid : [[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]]\n bucket_capacity : 2\n Output: 5\n \n Example 3:\n Input: \n grid : [[0,0,0], [0,0,0]]\n bucket_capacity : 5\n Output: 0\n\n Constraints:\n * all wells have the same length\n * 1 <= grid.length <= 10^2\n * 1 <= grid[:,1].length <= 10^2\n * grid[i][j] -> 0 | 1\n * 1 <= capacity <= 10\n */\nconst maxFill = (grid, capacity) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < grid.length; i++) {\n let m = 0\n for (let j = 0; j < grid[i].length; j++) {\n if (grid[i][j] == 1) { m++ }\n }\n while (m > 0) {\n m -= capacity;\n p++;\n }\n }\n return p\n}\n\n", "test": "const testMaxFill = () => {\n console.assert(\n maxFill(\n [\n [0, 0, 1, 0],\n [0, 1, 0, 0],\n [1, 1, 1, 1],\n ],\n 1\n ) === 6\n )\n console.assert(\n maxFill(\n [\n [0, 0, 1, 1],\n [0, 0, 0, 0],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n ],\n 2\n ) === 5\n )\n console.assert(\n maxFill(\n [\n [0, 0, 0],\n [0, 0, 0],\n ],\n 5\n ) === 0\n )\n console.assert(\n maxFill(\n [\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n ],\n 2\n ) === 4\n )\n console.assert(\n maxFill(\n [\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n ],\n 9\n ) === 2\n )\n}\n\ntestMaxFill()\n", "declaration": "\nconst maxFill = (grid, capacity) => {\n", "example_test": "const testMaxFill = () => {\n console.assert(\n maxFill(\n [\n [0, 0, 1, 0],\n [0, 1, 0, 0],\n [1, 1, 1, 1],\n ],\n 1\n ) === 6\n )\n console.assert(\n maxFill(\n [\n [0, 0, 1, 1],\n [0, 0, 0, 0],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n ],\n 2\n ) === 5\n )\n console.assert(\n maxFill(\n [\n [0, 0, 0],\n [0, 0, 0],\n ],\n 5\n ) === 0\n )\n}\ntestMaxFill()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < grid.length; i++) {\n let m = 0\n for (let j = 1; j < grid[i].length; j++) {\n if (grid[i][j] == 1) { m++ }\n }\n while (m > 0) {\n m -= capacity;\n p++;\n }\n }\n return p\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "maxFill"} -{"task_id": "JavaScript/116", "prompt": "/*\n In this Kata, you have to sort an array of non-negative integers according to\n number of ones in their binary representation in ascending order.\n For similar number of ones, sort based on decimal value.\n\n It must be implemented like this:\n >>> sortArray([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]\n >>> sortArray([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]\n >>> sortArray([1, 0, 2, 3, 4]) [0, 1, 2, 3, 4]\n */\nconst sortArray = (arr) => {\n", "canonical_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n let w1 = p[ind].toString(2)\n let f1 = 0\n for (let u = 0; u < w1.length; u++) {\n if (w1[u] == '1') { f1++ }\n }\n let w2 = p[k].toString(2)\n let f2 = 0\n for (let u = 0; u < w2.length; u++) {\n if (w2[u] == '1') { f2++ }\n }\n if (f2 < f1 || (f1 == f2 && p[k] < p[ind])) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "test": "const testSortArray = () => {\n console.assert(\n JSON.stringify(sortArray([1, 5, 2, 3, 4])) ===\n JSON.stringify([1, 2, 4, 3, 5])\n )\n\n console.assert(\n JSON.stringify(sortArray([-2, -3, -4, -5, -6])) ===\n JSON.stringify([-4, -2, -6, -5, -3])\n )\n console.assert(\n JSON.stringify(sortArray([1, 0, 2, 3, 4])) ===\n JSON.stringify([0, 1, 2, 4, 3])\n )\n console.assert(JSON.stringify(sortArray([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(sortArray([2, 5, 77, 4, 5, 3, 5, 7, 2, 3, 4])) ===\n JSON.stringify([2, 2, 4, 4, 3, 3, 5, 5, 5, 7, 77])\n )\n console.assert(\n JSON.stringify(sortArray([3, 6, 44, 12, 32, 5])) ===\n JSON.stringify([32, 3, 5, 6, 12, 44])\n )\n console.assert(\n JSON.stringify(sortArray([2, 4, 8, 16, 32])) ===\n JSON.stringify([2, 4, 8, 16, 32])\n )\n console.assert(\n JSON.stringify(sortArray([2, 4, 8, 16, 32])) ===\n JSON.stringify([2, 4, 8, 16, 32])\n )\n}\n\ntestSortArray()\n", "declaration": "\nconst sortArray = (arr) => {\n", "example_test": "const testSortArray = () => {\n console.assert(\n JSON.stringify(sortArray([1, 5, 2, 3, 4])) ===\n JSON.stringify([1, 2, 4, 3, 5])\n )\n console.assert(\n JSON.stringify(sortArray([-2, -3, -4, -5, -6])) ===\n JSON.stringify([-4, -2, -6, -5, -3])\n )\n console.assert(\n JSON.stringify(sortArray([1, 0, 2, 3, 4])) ===\n JSON.stringify([0, 1, 2, 4, 3])\n )\n}\ntestSortArray()\n", "buggy_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n let w1 = p[ind].toString(2)\n let f1 = 0\n for (let u = 0; u < w1.length; u++) {\n if (w1[u] == '1') { f1++ }\n }\n let w2 = p[ind].toString(2)\n let f2 = 0\n for (let u = 0; u < w2.length; u++) {\n if (w2[u] == '1') { f2++ }\n }\n if (f2 < f1 || (f1 == f2 && p[k] < p[ind])) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return arr\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "sortArray"} -{"task_id": "JavaScript/117", "prompt": "/*Given a string s and a natural number n, you have been tasked to implement \n a function that returns a list of all words from string s that contain exactly \n n consonants, in order these words appear in the string s.\n If the string s is empty then the function should return an empty list.\n Note: you may assume the input string contains only letters and spaces.\n Examples:\n selectWords(\"Mary had a little lamb\", 4) ==> [\"little\"]\n selectWords(\"Mary had a little lamb\", 3) ==> [\"Mary\")\n selectWords(\"simple white space\", 2) ==> []\n selectWords(\"Hello world\", 4) ==> [\"world\"]\n selectWords(\"Uncle sam\", 3) ==> [\"Uncle\"]\n */\nconst selectWords = (s, n) => {\n", "canonical_solution": " let t = s.split(/\\s/)\n if (s == '') { return [] }\n let k = []\n for (let i = 0; i < t.length; i++) {\n let l = 0\n for (let j = 0; j < t[i].length; j++) {\n if (t[i][j] != 'a' && t[i][j] != 'e' && t[i][j] != 'i' && t[i][j] != 'o' && t[i][j] != 'u' && t[i][j] != 'A' &&\n t[i][j] != 'U' && t[i][j] != 'O' && t[i][j] != 'I' && t[i][j] != 'E') {\n l++\n }\n }\n if (l == n) { k.push(t[i]) }\n }\n return k\n}\n\n", "test": "const testSelectWords = () => {\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 4)) ===\n JSON.stringify(['little'])\n )\n console.assert(\n JSON.stringify(selectWords('simple white space', 2)) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(selectWords('Hello world', 4)) === JSON.stringify(['world'])\n )\n console.assert(\n JSON.stringify(selectWords('Uncle sam', 3)) === JSON.stringify(['Uncle'])\n )\n\n console.assert(\n JSON.stringify(selectWords('a b c d e f', 1)) ===\n JSON.stringify(['b', 'c', 'd', 'f'])\n )\n\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 3)) ===\n JSON.stringify(['Mary', 'lamb'])\n )\n console.assert(JSON.stringify(selectWords('', 4)) === JSON.stringify([]))\n}\n\ntestSelectWords()\n", "declaration": "\nconst selectWords = (s, n) => {\n", "example_test": "const testSelectWords = () => {\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 4)) ===\n JSON.stringify(['little'])\n )\n console.assert(\n JSON.stringify(selectWords('simple white space', 2)) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(selectWords('Hello world', 4)) === JSON.stringify(['world'])\n )\n console.assert(\n JSON.stringify(selectWords('Uncle sam', 3)) === JSON.stringify(['Uncle'])\n )\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 3)) ===\n JSON.stringify(['Mary', 'lamb'])\n )\n}\ntestSelectWords()\n", "buggy_solution": " let t = s.split(/\\s/)\n if (s == '') { return [] }\n let k = []\n for (let i = 0; i < t.length; i++) {\n let l = 0\n for (let j = 0; j < t[i].length; j++) {\n if (t[i][j] != 'a' || t[i][j] != 'e' || t[i][j] != 'i' || t[i][j] != 'o' || t[i][j] != 'u' || t[i][j] != 'A' ||\n t[i][j] != 'U' || t[i][j] != 'O' || t[i][j] != 'I' || t[i][j] != 'E') {\n l++\n }\n }\n if (l == n) { k.push(t[i]) }\n }\n return k\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "selectWords"} -{"task_id": "JavaScript/118", "prompt": "/*You are given a word. Your task is to find the closest vowel that stands between \n two consonants from the right side of the word (case sensitive).\n \n Vowels in the beginning and ending doesn't count. Return empty string if you didn't\n find any vowel met the above condition. \n\n You may assume that the given string contains English letter only.\n\n Example:\n getClosestVowel(\"yogurt\") ==> \"u\"\n getClosestVowel(\"FULL\") ==> \"U\"\n getClosestVowel(\"quick\") ==> \"\"\n getClosestVowel(\"ab\") ==> \"\"\n */\nconst getClosestVowel = (word) => {\n", "canonical_solution": " for (let i = word.length - 2; i > 0; i--) {\n if (\n !(word[i] != 'a' && word[i] != 'e' && word[i] != 'i' && word[i] != 'o' && word[i] != 'u' && word[i] != 'A' &&\n word[i] != 'U' && word[i] != 'O' && word[i] != 'I' && word[i] != 'E')\n &&\n (word[i + 1] != 'a' && word[i + 1] != 'e' && word[i + 1] != 'i' && word[i + 1] != 'o' && word[i + 1] != 'u' && word[i + 1] != 'A' &&\n word[i + 1] != 'U' && word[i + 1] != 'O' && word[i + 1] != 'I' && word[i + 1] != 'E')\n &&\n (word[i - 1] != 'a' && word[i - 1] != 'e' && word[i - 1] != 'i' && word[i - 1] != 'o' && word[i - 1] != 'u' && word[i - 1] != 'A' &&\n word[i - 1] != 'U' && word[i - 1] != 'O' && word[i - 1] != 'I' && word[i - 1] != 'E')\n ) {\n return word[i]\n }\n }\n return ''\n}\n\n", "test": "const testGetClosestVowel = () => {\n console.assert(getClosestVowel('yogurt') === 'u')\n console.assert(getClosestVowel('full') === 'u')\n console.assert(getClosestVowel('easy') === '')\n console.assert(getClosestVowel('eAsy') === '')\n console.assert(getClosestVowel('ali') === '')\n console.assert(getClosestVowel('bad') === 'a')\n console.assert(getClosestVowel('most') === 'o')\n console.assert(getClosestVowel('ab') === '')\n console.assert(getClosestVowel('ba') === '')\n console.assert(getClosestVowel('quick') === '')\n console.assert(getClosestVowel('anime') === 'i')\n console.assert(getClosestVowel('Asia') === '')\n console.assert(getClosestVowel('Above') === 'o')\n}\n\ntestGetClosestVowel()\n", "declaration": "\nconst getClosestVowel = (word) => {\n", "example_test": "const testGetClosestVowel = () => {\n console.assert(getClosestVowel('yogurt') === 'u')\n console.assert(getClosestVowel('FULL') === 'U')\n console.assert(getClosestVowel('ab') === '')\n console.assert(getClosestVowel('quick') === '')\n}\ntestGetClosestVowel()\n", "buggy_solution": " for (let i = word.length - 2; i > 0; i--) {\n if (\n (word[i] != 'a' && word[i] != 'e' && word[i] != 'i' && word[i] != 'o' && word[i] != 'u' && word[i] != 'A' &&\n word[i] != 'U' && word[i] != 'O' && word[i] != 'I' && word[i] != 'E')\n &&\n (word[i + 1] != 'a' && word[i + 1] != 'e' && word[i + 1] != 'i' && word[i + 1] != 'o' && word[i + 1] != 'u' && word[i + 1] != 'A' &&\n word[i + 1] != 'U' && word[i + 1] != 'O' && word[i + 1] != 'I' && word[i + 1] != 'E')\n &&\n (word[i - 1] != 'a' && word[i - 1] != 'e' && word[i - 1] != 'i' && word[i - 1] != 'o' && word[i - 1] != 'u' && word[i - 1] != 'A' &&\n word[i - 1] != 'U' && word[i - 1] != 'O' && word[i - 1] != 'I' && word[i - 1] != 'E')\n ) {\n return word[i]\n }\n }\n return ' '\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "getClosestVowel"} -{"task_id": "JavaScript/119", "prompt": "/* You are given a list of two strings, both strings consist of open\n parentheses '(' or close parentheses ')' only.\n Your job is to check if it is possible to concatenate the two strings in\n some order, that the resulting string will be good.\n A string S is considered to be good if and only if all parentheses in S\n are balanced. For example: the string '(())()' is good, while the string\n '())' is not.\n Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.\n Examples:\n matchParens(['()(', ')']) == 'Yes'\n matchParens([')', ')']) == 'No'\n */\nconst matchParens = (lst) => {\n", "canonical_solution": " let w1 = lst[0] + lst[1]\n let y = 0\n let u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'Yes' }\n w1 = lst[1] + lst[0]\n y = 0\n u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'Yes' }\n return 'No'\n}\n\n", "test": "const testMatchParens = () => {\n console.assert(matchParens(['()(', ')']) === 'Yes')\n console.assert(matchParens([')', ')']) === 'No')\n console.assert(matchParens(['(()(())', '())())']) === 'No')\n console.assert(matchParens([')())', '(()()(']) === 'Yes')\n console.assert(matchParens(['(())))', '(()())((']) === 'Yes')\n console.assert(matchParens(['()', '())']) === 'No')\n console.assert(matchParens(['(()(', '()))()']) === 'Yes')\n console.assert(matchParens(['((((', '((())']) === 'No')\n console.assert(matchParens([')(()', '(()(']) === 'No')\n console.assert(matchParens([')(', ')(']) === 'No')\n console.assert(matchParens(['(', ')']) === 'Yes')\n console.assert(matchParens([')', '(']) === 'Yes')\n}\ntestMatchParens()\n", "declaration": "\nconst matchParens = (lst) => {\n", "example_test": "const testMatchParens = () => {\n console.assert(matchParens(['()(', ')']) === 'Yes')\n console.assert(matchParens([')', ')']) === 'No')\n}\ntestMatchParens()\n", "buggy_solution": " let w1 = lst[0] + lst[1]\n let y = 0\n let u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'yes' }\n w1 = lst[1] + lst[0]\n y = 0\n u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'no' }\n return 'yes'\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "matchParens"} -{"task_id": "JavaScript/120", "prompt": "/*\n Given an array arr of integers and a positive integer k, return a sorted list \n of length k with the maximum k numbers in arr.\n\n Example 1:\n\n Input: arr = [-3, -4, 5], k = 3\n Output: [-4, -3, 5]\n\n Example 2:\n\n Input: arr = [4, -4, 4], k = 2\n Output: [4, 4]\n\n Example 3:\n\n Input: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1\n Output: [2]\n\n Note:\n 1. The length of the array will be in the range of [1, 1000].\n 2. The elements in the array will be in the range of [-1000, 1000].\n 3. 0 <= k <= len(arr)\n */\nconst maximum = (arr, k) => {\n", "canonical_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n if (k == 0) { return [] }\n return p.slice(-k)\n}\n\n", "test": "const testMaximum = () => {\n console.assert(\n JSON.stringify(maximum([-3, -4, 5], 3)) === JSON.stringify([-4, -3, 5])\n )\n console.assert(\n JSON.stringify(maximum([4, -4, 4], 2)) === JSON.stringify([4, 4])\n )\n console.assert(\n JSON.stringify(maximum([-3, 2, 1, 2, -1, -2, 1], 1)) === JSON.stringify([2])\n )\n console.assert(\n JSON.stringify(maximum([123, -123, 20, 0, 1, 2, -3], 3)) ===\n JSON.stringify([2, 20, 123])\n )\n console.assert(\n JSON.stringify(maximum([-123, 20, 0, 1, 2, -3], 4)) ===\n JSON.stringify([0, 1, 2, 20])\n )\n console.assert(\n JSON.stringify(maximum([5, 15, 0, 3, -13, -8, 0], 7)) ===\n JSON.stringify([-13, -8, 0, 0, 3, 5, 15])\n )\n console.assert(\n JSON.stringify(maximum([-1, 0, 2, 5, 3, -10], 2)) === JSON.stringify([3, 5])\n )\n console.assert(\n JSON.stringify(maximum([1, 0, 5, -7], 1)) === JSON.stringify([5])\n )\n console.assert(JSON.stringify(maximum([4, -4], 2)) === JSON.stringify([-4, 4]))\n console.assert(\n JSON.stringify(maximum([-10, 10], 2)) === JSON.stringify([-10, 10])\n )\n console.assert(\n JSON.stringify(maximum([1, 2, 3, -23, 243, -400, 0], 0)) ===\n JSON.stringify([])\n )\n}\n\ntestMaximum()\n", "declaration": "\nconst maximum = (arr, k) => {\n", "example_test": "const testMaximum = () => {\n console.assert(\n JSON.stringify(maximum([-3, -4, 5], 3)) === JSON.stringify([-4, -3, 5])\n )\n console.assert(\n JSON.stringify(maximum([4, -4, 4], 2)) === JSON.stringify([4, 4])\n )\n console.assert(\n JSON.stringify(maximum([-3, 2, 1, 2, -1, -2, 1], 1)) === JSON.stringify([2])\n )\n}\ntestMaximum()\n", "buggy_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n p[j] = p[ind]\n }\n }\n if (k == 0) { return [] }\n return p.slice(-k)\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "maximum"} -{"task_id": "JavaScript/121", "prompt": "/*Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions.\n \n\n Examples\n solution([5, 8, 7, 1]) ==> 12\n solution([3, 3, 3, 3, 3]) ==> 9\n solution([30, 13, 24, 321]) ==>0\n */\nconst solution = (lst) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < lst.length; i += 2) {\n if (lst[i] % 2 == 1) {\n p += lst[i]\n }\n }\n return p\n}\n\n", "test": "const testSolution = () => {\n console.assert(solution([5, 8, 7, 1]) === 12)\n console.assert(solution([3, 3, 3, 3, 3]) === 9)\n console.assert(solution([30, 13, 24, 321]) === 0)\n console.assert(solution([5, 9]) === 5)\n console.assert(solution([2, 4, 8]) === 0)\n console.assert(solution([30, 13, 23, 32]) === 23)\n console.assert(solution([3, 13, 2, 9]) === 3)\n}\n\ntestSolution()\n", "declaration": "\nconst solution = (lst) => {\n", "example_test": "const testSolution = () => {\n console.assert(solution([5, 8, 7, 1]) === 12)\n console.assert(solution([3, 3, 3, 3, 3]) === 9)\n console.assert(solution([30, 13, 24, 321]) === 0)\n}\ntestSolution()\n", "buggy_solution": " let p = 1\n for (let i = 0; i < lst.length; i += 2) {\n if (lst[i] % 2 == 1) {\n p += lst[i]\n }\n }\n return p\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "solution"} -{"task_id": "JavaScript/122", "prompt": "/*\n Given a non-empty array of integers arr and an integer k, return\n the sum of the elements with at most two digits from the first k elements of arr.\n\n Example:\n\n Input: arr = [111,21,3,4000,5,6,7,8,9], k = 4\n Output: 24 # sum of 21 + 3\n\n Constraints:\n 1. 1 <= len(arr) <= 100\n 2. 1 <= k <= len(arr)\n */\nconst addElements = (arr, k) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < k; i++) {\n if (arr[i] < 100 && arr[i] > -100) { p += arr[i] }\n }\n return p\n}\n\n", "test": "const testAddElements = () => {\n console.assert(addElements([1, -2, -3, 41, 57, 76, 87, 88, 99], 3) === -4)\n console.assert(addElements([111, 121, 3, 4000, 5, 6], 2) === 0)\n console.assert(addElements([11, 21, 3, 90, 5, 6, 7, 8, 9], 4) === 125)\n console.assert(addElements([111, 21, 3, 4000, 5, 6, 7, 8, 9], 4) === 24)\n console.assert(addElements([1], 1) === 1)\n}\n\ntestAddElements()\n", "declaration": "\nconst addElements = (arr, k) => {\n", "example_test": "const testAddElements = () => {\n console.assert(addElements([111, 21, 3, 4000, 5, 6, 7, 8, 9], 4) === 24)\n}\ntestAddElements()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] < 100 && arr[i] > -100) { p += arr[i] }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "addElements"} -{"task_id": "JavaScript/123", "prompt": "/*\n Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence.\n\n The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined\n as follows: start with any positive integer n. Then each term is obtained from the \n previous term as follows: if the previous term is even, the next term is one half of \n the previous term. If the previous term is odd, the next term is 3 times the previous\n term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.\n\n Note: \n 1. Collatz(1) is [1].\n 2. returned list sorted in increasing order.\n\n For example:\n getOddCollatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.\n */\nconst getOddCollatz = (n) => {\n", "canonical_solution": " let p = []\n let t = n\n while (1) {\n let u = 0\n for (let i = 0; i < p.length; i++) {\n if (t == p[i]) {\n u = 1\n break;\n }\n }\n if (u == 1) { break }\n if (t % 2 == 1) { p.push(t); t = 3 * t + 1 }\n else { t = t / 2 }\n }\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "test": "const testGetOddCollatz = () => {\n console.assert(\n JSON.stringify(getOddCollatz(14)) === JSON.stringify([1, 5, 7, 11, 13, 17])\n )\n console.assert(JSON.stringify(getOddCollatz(5)) === JSON.stringify([1, 5]))\n console.assert(JSON.stringify(getOddCollatz(12)) === JSON.stringify([1, 3, 5]))\n console.assert(JSON.stringify(getOddCollatz(1)) === JSON.stringify([1]))\n}\n\ntestGetOddCollatz()\n", "declaration": "\nconst getOddCollatz = (n) => {\n", "example_test": "const testGetOddCollatz = () => {\n console.assert(JSON.stringify(getOddCollatz(5)) === JSON.stringify([1, 5]))\n}\ntestGetOddCollatz()\n", "buggy_solution": " let p = []\n let t = n\n while (1) {\n let u = 0\n for (let i = 0; i < p.length; i++) {\n if (t == p[i]) {\n u = 1\n break;\n }\n }\n if (u == 1) { break }\n if (t % 2 == 1) { p.push(t); t = 2 * t + 1 }\n else { t = t / 2 }\n }\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "getOddCollatz"} -{"task_id": "JavaScript/124", "prompt": "/*You have to write a function which validates a given date string and\n returns true if the date is valid otherwise false.\n The date is valid if all of the following rules are satisfied:\n 1. The date string is not empty.\n 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n 3. The months should not be less than 1 or higher than 12.\n 4. The date should be in the format: mm-dd-yyyy\n\n for example: \n validDate('03-11-2000') => true\n\n validDate('15-01-2012') => false\n\n validDate('04-0-2040') => false\n\n validDate('06-04-2020') => true\n\n validDate('06/04/2020') => false\n */\nconst validDate = (date) => {\n", "canonical_solution": " let t = date.split(/-/)\n if (t.length != 3) { return false }\n if (t[0] < 1 || t[0] > 12 || t[1] < 1) { return false }\n if (t[0] == 2 && t[1] > 29) { return false }\n if ((t[0] == 1 || t[0] == 3 || t[0] == 5 || t[0] == 7 || t[0] == 8 || t[0] == 10 || t[0] == 12) && t[1] > 31) { return false }\n if ((t[0] == 4 || t[0] == 6 || t[0] == 9 || t[0] == 11) && t[1] > 30) { return false }\n return true\n}\n\n", "test": "const testValidDate = () => {\n console.assert(validDate('03-11-2000') === true)\n console.assert(validDate('15-01-2012') === false)\n console.assert(validDate('04-0-2040') === false)\n console.assert(validDate('06-04-2020') === true)\n console.assert(validDate('01-01-2007') === true)\n console.assert(validDate('03-32-2011') === false)\n console.assert(validDate('') === false)\n console.assert(validDate('04-31-3000') === false)\n console.assert(validDate('06-06-2005') === true)\n console.assert(validDate('21-31-2000') === false)\n console.assert(validDate('04-12-2003') === true)\n console.assert(validDate('04122003') === false)\n console.assert(validDate('20030412') === false)\n console.assert(validDate('2003-04') === false)\n console.assert(validDate('2003-04-12') === false)\n console.assert(validDate('04-2003') === false)\n}\n\ntestValidDate()\n", "declaration": "\nconst validDate = (date) => {\n", "example_test": "const testValidDate = () => {\n console.assert(validDate('03-11-2000') === true)\n console.assert(validDate('15-01-2012') === false)\n console.assert(validDate('04-0-2040') === false)\n console.assert(validDate('06-04-2020') === true)\n console.assert(validDate('06/04/2020') === false)\n}\ntestValidDate()\n", "buggy_solution": " let t = date.split(/-/)\n if (t.length != 3) { return false }\n if (t[1] < 1 || t[1] > 12 || t[0] < 1) { return false }\n if (t[1] == 2 && t[0] > 29) { return false }\n if ((t[1] == 1 || t[1] == 3 || t[1] == 5 || t[1] == 7 || t[1] == 8 || t[1] == 10 || t[1] == 12) && t[0] > 31) { return false }\n if ((t[1] == 4 || t[1] == 6 || t[1] == 9 || t[1] == 11) && t[0] > 30) { return false }\n return true\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "validDate"} -{"task_id": "JavaScript/125", "prompt": "/* Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you\n should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the\n alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25\n Examples\n splitWords(\"Hello world!\") \u279e [\"Hello\", \"world!\"]\n splitWords(\"Hello,world!\") \u279e [\"Hello\", \"world!\"]\n splitWords(\"abcdef\") == 3\n */\nconst splitWords = (txt) => {\n", "canonical_solution": " let t = txt.split(/\\s/)\n if (t.length > 1) {\n return t\n } else {\n t = txt.split(/,/)\n if (t.length > 1) {\n return t\n } else {\n let p = 0\n for (let i = 0; i < txt.length; i++) {\n let m = txt[i].charCodeAt()\n if (m >= 97 && m <= 122 && m % 2 == 0) {\n p++\n }\n }\n return p\n }\n }\n}\n\n", "test": "const testSplitWords = () => {\n console.assert(\n JSON.stringify(splitWords('Hello world!')) ===\n JSON.stringify(['Hello', 'world!'])\n )\n console.assert(\n JSON.stringify(splitWords('Hello,world!')) ===\n JSON.stringify(['Hello', 'world!'])\n )\n console.assert(\n JSON.stringify(splitWords('Hello world,!')) ===\n JSON.stringify(['Hello', 'world,!'])\n )\n console.assert(\n JSON.stringify(splitWords('Hello,Hello,world !')) ===\n JSON.stringify(['Hello,Hello,world', '!'])\n )\n console.assert(JSON.stringify(splitWords('abcdef')) === JSON.stringify(3))\n console.assert(JSON.stringify(splitWords('aaabb')) === JSON.stringify(2))\n console.assert(JSON.stringify(splitWords('aaaBb')) === JSON.stringify(1))\n console.assert(JSON.stringify(splitWords('')) === JSON.stringify(0))\n}\n\ntestSplitWords()\n", "declaration": "\nconst splitWords = (txt) => {\n", "example_test": "const testSplitWords = () => {\n console.assert(\n JSON.stringify(splitWords('Hello world!')) ===\n JSON.stringify(['Hello', 'world!'])\n )\n console.assert(\n JSON.stringify(splitWords('Hello,world!')) ===\n JSON.stringify(['Hello', 'world!'])\n )\n console.assert(JSON.stringify(splitWords('abcdef')) === JSON.stringify(3))\n}\ntestSplitWords()\n", "buggy_solution": " let t = txt.split(/,/)\n if (t.length > 1) {\n return t\n } else {\n t = txt.split(/\\s/)\n if (t.length > 1) {\n return t\n } else {\n let p = 0\n for (let i = 0; i < txt.length; i++) {\n let m = txt[i].charCodeAt()\n if (m >= 97 && m <= 122 && m % 2 == 0) {\n p++\n }\n }\n return p\n }\n }\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "splitWords"} -{"task_id": "JavaScript/126", "prompt": "/* Given a list of numbers, return whether or not they are sorted\n in ascending order. If list has more than 1 duplicate of the same\n number, return false. Assume no negative numbers and only integers.\n Examples\n isSorted([5]) \u279e true\n isSorted([1, 2, 3, 4, 5]) \u279e true\n isSorted([1, 3, 2, 4, 5]) \u279e false\n isSorted([1, 2, 3, 4, 5, 6]) \u279e true\n isSorted([1, 2, 3, 4, 5, 6, 7]) \u279e true\n isSorted([1, 3, 2, 4, 5, 6, 7]) \u279e false\n isSorted([1, 2, 2, 3, 3, 4]) \u279e true\n isSorted([1, 2, 2, 2, 3, 4]) \u279e false\n */\nconst isSorted = (lst) => {\n", "canonical_solution": " if (lst.length == 0) { return true }\n let dup = 1\n let pre = lst[0]\n for (let i = 1; i < lst.length; i++) {\n if (lst[i] < pre) { return false }\n if (lst[i] == pre) {\n dup += 1;\n if (dup == 3) { return false }\n } else {\n pre = lst[i]\n dup = 1\n }\n }\n return true\n}\n\n", "test": "const testIsSorted = () => {\n console.assert(isSorted([5]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5]) === false)\n console.assert(isSorted([1, 2, 3, 4, 5, 6]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5, 6, 7]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5, 6, 7]) === false)\n console.assert(isSorted([]) === true)\n console.assert(isSorted([1]) === true)\n console.assert(isSorted([3, 2, 1]) === false)\n console.assert(isSorted([1, 2, 2, 2, 3, 4]) === false)\n console.assert(isSorted([1, 2, 3, 3, 3, 4]) === false)\n console.assert(isSorted([1, 2, 2, 3, 3, 4]) === true)\n console.assert(isSorted([1, 2, 3, 4]) === true)\n}\n\ntestIsSorted()\n", "declaration": "\nconst isSorted = (lst) => {\n", "example_test": "const testIsSorted = () => {\n console.assert(isSorted([5]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5]) === false)\n console.assert(isSorted([1, 2, 3, 4, 5, 6]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5, 6, 7]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5, 6, 7]) === false)\n console.assert(isSorted([1, 2, 2, 2, 3, 4]) === false)\n console.assert(isSorted([1, 2, 2, 3, 3, 4]) === true)\n}\ntestIsSorted()\n", "buggy_solution": " if (lst.length == 0) { return true }\n let dup = 1\n let pre = lst[0]\n for (let i = 1; i < lst.length; i++) {\n if (lst[i] < pre) { return false }\n if (lst[i] == pre) {\n dup += 1;\n if (dup == 3) { return false }\n } else {\n pre = lst[i]\n }\n }\n return true\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "isSorted"} -{"task_id": "JavaScript/127", "prompt": "/*You are given two intervals,\n where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\n The given intervals are closed which means that the interval (start, end)\n includes both start and end.\n For each given interval, it is assumed that its start is less or equal its end.\n Your task is to determine whether the length of intersection of these two \n intervals is a prime number.\n Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\n which its length is 1, which not a prime number.\n If the length of the intersection is a prime number, return \"YES\",\n otherwise, return \"NO\".\n If the two intervals don't intersect, return \"NO\".\n\n\n [input/output] samples:\n intersection((1, 2), (2, 3)) ==> \"NO\"\n intersection((-1, 1), (0, 4)) ==> \"NO\"\n intersection((-3, -1), (-5, 5)) ==> \"YES\"\n */\nconst intersection = (interval1, interval2) => {\n", "canonical_solution": " let lo = interval1[0]\n if (interval2[0] > lo) { lo = interval2[0] }\n let hi = interval1[1]\n if (interval2[1] < hi) { hi = interval2[1] }\n let len = 0\n if (hi > lo) { len = hi - lo }\n if (len == 1 || len == 0) { return 'NO' }\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { return 'NO' }\n }\n return 'YES'\n}\n\n", "test": "const testIntersection = () => {\n console.assert(intersection([1, 2], [2, 3]) === 'NO')\n console.assert(intersection([-1, 1], [0, 4]) === 'NO')\n console.assert(intersection([-3, -1], [-5, 5]) === 'YES')\n console.assert(intersection([-2, 2], [-4, 0]) === 'YES')\n console.assert(intersection([-11, 2], [-1, -1]) === 'NO')\n console.assert(intersection([1, 2], [3, 5]) === 'NO')\n console.assert(intersection([1, 2], [1, 2]) === 'NO')\n console.assert(intersection([-2, -2], [-3, -2]) === 'NO')\n}\n\ntestIntersection()\n", "declaration": "\nconst intersection = (interval1, interval2) => {\n", "example_test": "const testIntersection = () => {\n console.assert(intersection([1, 2], [2, 3]) === 'NO')\n console.assert(intersection([-1, 1], [0, 4]) === 'NO')\n console.assert(intersection([-3, -1], [-5, 5]) === 'YES')\n}\ntestIntersection()\n", "buggy_solution": " let lo = interval1[0]\n if (interval2[0] > lo) { lo = interval2[0] }\n let hi = interval1[1]\n if (interval2[1] < hi) { hi = interval2[1] }\n let len = 0\n if (hi > lo) { len = hi }\n if (len == 1 || len == 0) { return 'NO' }\n return 'YES'\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "intersection"} -{"task_id": "JavaScript/128", "prompt": "/*\n You are given an array arr of integers and you need to return\n sum of magnitudes of integers multiplied by product of all signs\n of each number in the array, represented by 1, -1 or 0.\n Note: return null for empty arr.\n\n Example:\n >>> prodSigns([1, 2, 2, -4]) == -9\n >>> prodSigns([0, 1]) == 0\n >>> prodSigns([]) == null\n */\nconst prodSigns = (arr) => {\n", "canonical_solution": " if (arr.length == 0) { return null }\n let n = 1\n let s = 0\n for (let i = 0; i < arr.length; i++) {\n s += arr[i]\n if (arr[i] == 0) { return 0 }\n if (arr[i] < 0) { n = -n; s -= 2 * arr[i] }\n }\n return s * n\n}\n\n", "test": "const testProdSigns = () => {\n console.assert(prodSigns([1, 2, 2, -4]) === -9)\n console.assert(prodSigns([0, 1]) === 0)\n console.assert(prodSigns([1, 1, 1, 2, 3, -1, 1]) === -10)\n console.assert(prodSigns([]) === null)\n console.assert(prodSigns([2, 4, 1, 2, -1, -1, 9]) === 20)\n console.assert(prodSigns([-1, 1, -1, 1]) === 4)\n console.assert(prodSigns([-1, 1, 1, 1]) === -4)\n console.assert(prodSigns([-1, 1, 1, 0]) === 0)\n}\n\ntestProdSigns()\n", "declaration": "\nconst prodSigns = (arr) => {\n", "example_test": "const testProdSigns = () => {\n console.assert(prodSigns([1, 2, 2, -4]) === -9)\n console.assert(prodSigns([0, 1]) === 0)\n console.assert(prodSigns([]) === null)\n}\ntestProdSigns()\n", "buggy_solution": " if (arr.length == 0) { return null }\n let n = 1\n let s = 0\n for (let i = 0; i < arr.length; i++) {\n s += arr[i]\n if (arr[i] == 0) { return 0 }\n if (arr[i] < 0) { n = -n; s -= 2 * arr[i] }\n }\n return s * n * 2\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "prodSigns"} -{"task_id": "JavaScript/129", "prompt": "/*\n Given a grid with N rows and N columns (N >= 2) and a positive integer k, \n each cell of the grid contains a value. Every integer in the range [1, N * N]\n inclusive appears exactly once on the cells of the grid.\n\n You have to find the minimum path of length k in the grid. You can start\n from any cell, and in each step you can move to any of the neighbor cells,\n in other words, you can go to cells which share an edge with you current\n cell.\n Please note that a path of length k means visiting exactly k cells (not\n necessarily distinct).\n You CANNOT go off the grid.\n A path A (of length k) is considered less than a path B (of length k) if\n after making the ordered lists of the values on the cells that A and B go\n through (let's call them lst_A and lst_B), lst_A is lexicographically less\n than lst_B, in other words, there exist an integer index i (1 <= i <= k)\n such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\n lst_A[j] = lst_B[j].\n It is guaranteed that the answer is unique.\n Return an ordered list of the values on the cells that the minimum path go through.\n\n Examples:\n\n Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3\n Output: [1, 2, 1]\n\n Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1\n Output: [1]\n */\nconst minPath = (grid, k) => {\n", "canonical_solution": " let m = 0\n let n = 0\n for (let i = 0; i < grid.length; i++) {\n for (let j = 0; j < grid.length; j++) {\n if (grid[i][j] == 1) {\n m = i;\n n = j;\n break;\n }\n }\n }\n let min = grid.length * grid.length\n if (m > 0 && grid[m - 1][n] < min) { min = grid[m - 1][n] }\n if (n > 0 && grid[m][n - 1] < min) { min = grid[m][n - 1] }\n if (m < grid.length - 1 && grid[m + 1][n] < min) { min = grid[m + 1][n] }\n if (n < grid.length - 1 && grid[m][n + 1] < min) { min = grid[m][n + 1] }\n let p = []\n for (let i = 0; i < k; i++) {\n if (i % 2 == 0) { p.push(1) }\n else { p.push(min) }\n }\n return p\n}\n\n", "test": "const testMinPath = () => {\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9],\n ],\n 3\n )\n ) === JSON.stringify([1, 2, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [5, 9, 3],\n [4, 1, 6],\n [7, 8, 2],\n ],\n 1\n )\n ) === JSON.stringify([1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n ],\n 4\n )\n ) === JSON.stringify([1, 2, 1, 2])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [6, 4, 13, 10],\n [5, 7, 12, 1],\n [3, 16, 11, 15],\n [8, 14, 9, 2],\n ],\n 7\n )\n ) === JSON.stringify([1, 10, 1, 10, 1, 10, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [8, 14, 9, 2],\n [6, 4, 13, 15],\n [5, 7, 1, 12],\n [3, 10, 11, 16],\n ],\n 5\n )\n ) === JSON.stringify([1, 7, 1, 7, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [11, 8, 7, 2],\n [5, 16, 14, 4],\n [9, 3, 15, 6],\n [12, 13, 10, 1],\n ],\n 9\n )\n ) === JSON.stringify([1, 6, 1, 6, 1, 6, 1, 6, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [12, 13, 10, 1],\n [9, 3, 15, 6],\n [5, 16, 14, 4],\n [11, 8, 7, 2],\n ],\n 12\n )\n ) === JSON.stringify([1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [2, 7, 4],\n [3, 1, 5],\n [6, 8, 9],\n ],\n 8\n )\n ) === JSON.stringify([1, 3, 1, 3, 1, 3, 1, 3])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [6, 1, 5],\n [3, 8, 9],\n [2, 7, 4],\n ],\n 8\n )\n ) === JSON.stringify([1, 5, 1, 5, 1, 5, 1, 5])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2],\n [3, 4],\n ],\n 10\n )\n ) === JSON.stringify([1, 2, 1, 2, 1, 2, 1, 2, 1, 2])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 3],\n [4, 2],\n ],\n 10\n )\n ) === JSON.stringify([1, 3, 1, 3, 1, 3, 1, 3, 1, 3])\n )\n}\n\ntestMinPath()\n", "declaration": "\nconst minPath = (grid, k) => {\n", "example_test": "const testMinPath = () => {\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9],\n ],\n 3\n )\n ) === JSON.stringify([1, 2, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [5, 9, 3],\n [4, 1, 6],\n [7, 8, 2],\n ],\n 1\n )\n ) === JSON.stringify([1])\n )\n}\ntestMinPath()\n", "buggy_solution": " let m = 0\n let n = 0\n for (let i = 0; i < grid.length; i++) {\n for (let j = 0; j < grid.length; j++) {\n if (grid[i][j] == 1) {\n m = i;\n n = j;\n break;\n }\n }\n }\n let min = grid.length * grid.length\n if (m > 0 && grid[m - 1][n] < min) { min = grid[m][n] }\n if (n > 0 && grid[m][n - 1] < min) { min = grid[m][n] }\n if (m < grid.length - 1 && grid[m + 1][n] < min) { min = grid[m][n] }\n if (n < grid.length - 1 && grid[m][n + 1] < min) { min = grid[m][n] }\n let p = []\n for (let i = 0; i < k; i++) {\n if (i % 2 == 0) { p.push(1) }\n else { p.push(min) }\n }\n return p\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "minPath"} -{"task_id": "JavaScript/130", "prompt": "/*Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in \n the last couple centuries. However, what people don't know is Tribonacci sequence.\n Tribonacci sequence is defined by the recurrence:\n tri(1) = 3\n tri(n) = 1 + n / 2, if n is even.\n tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\n For example:\n tri(2) = 1 + (2 / 2) = 2\n tri(4) = 3\n tri(3) = tri(2) + tri(1) + tri(4)\n = 2 + 3 + 3 = 8 \n You are given a non-negative integer number n, you have to a return a list of the \n first n + 1 numbers of the Tribonacci sequence.\n Examples:\n tri(3) = [1, 3, 2, 8]\n */\nconst tri = (n) => {\n", "canonical_solution": " if (n == 0) { return [1] }\n if (n == 1) { return [1, 3] }\n let p = [1, 3]\n for (let i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n p.push(1 + i / 2)\n }\n else {\n p.push(p[i - 2] + p[i - 1] + 1 + (i + 1) / 2)\n }\n }\n return p\n}\n\n", "test": "const testTri = () => {\n console.assert(JSON.stringify(tri(3)) === JSON.stringify([1, 3, 2.0, 8.0]))\n\n console.assert(\n JSON.stringify(tri(4)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0])\n )\n console.assert(\n JSON.stringify(tri(5)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0])\n )\n console.assert(\n JSON.stringify(tri(6)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0])\n )\n console.assert(\n JSON.stringify(tri(7)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0])\n )\n console.assert(\n JSON.stringify(tri(8)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0])\n )\n console.assert(\n JSON.stringify(tri(9)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0])\n )\n console.assert(\n JSON.stringify(tri(20)) ===\n JSON.stringify([\n 1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0, 6.0, 48.0, 7.0, 63.0,\n 8.0, 80.0, 9.0, 99.0, 10.0, 120.0, 11.0,\n ])\n )\n console.assert(JSON.stringify(tri(0)) === JSON.stringify([1]))\n console.assert(JSON.stringify(tri(1)) === JSON.stringify([1, 3]))\n}\n\ntestTri()\n", "declaration": "\nconst tri = (n) => {\n", "example_test": "const testTri = () => {\n console.assert(JSON.stringify(tri(3)) === JSON.stringify([1, 3, 2.0, 8.0]))\n}\ntestTri()\n", "buggy_solution": " if (n == 0) { return [1] }\n if (n == 1) { return [1, 3] }\n let p = [1, 3]\n for (let i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n p.push(1 + i / 2)\n }\n else {\n p.push(p[i - 2] + p[i - 1] + 1 + i + (i + 1) / 2)\n }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "tri"} -{"task_id": "JavaScript/131", "prompt": "/*Given a positive integer n, return the product of the odd digits.\n Return 0 if all digits are even.\n For example:\n digits(1) == 1\n digits(4) == 0\n digits(235) == 15\n */\nconst digits = (n) => {\n", "canonical_solution": " let p = 1\n let k = 1\n while (n > 0) {\n let y = n % 10\n if (y % 2 == 1) {\n p *= y; k = 0;\n }\n n = (n - n % 10) / 10\n }\n if (k == 0) { return p }\n return 0\n}\n\n", "test": "const testDigits = () => {\n console.assert(digits(5) === 5)\n console.assert(digits(54) === 5)\n console.assert(digits(120) === 1)\n console.assert(digits(5014) === 5)\n console.assert(digits(98765) === 315)\n console.assert(digits(5576543) === 2625)\n console.assert(digits(2468) === 0)\n}\n\ntestDigits()\n", "declaration": "\nconst digits = (n) => {\n", "example_test": "const testDigits = () => {\n console.assert(digits(1) === 1)\n console.assert(digits(4) === 0)\n console.assert(digits(235) === 15)\n}\ntestDigits()\n", "buggy_solution": " let p = 1\n let k = 1\n while (n > 0) {\n let y = n % 10\n if (y % 2 == 1) {\n p *= p*y; k = 0;\n }\n n = (n - n % 10) / 10\n }\n if (k == 0) { return p }\n return 0\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "digits"} -{"task_id": "JavaScript/132", "prompt": "/*\n Create a function that takes a string as input which contains only square brackets.\n The function should return true if and only if there is a valid subsequence of brackets\n where at least one bracket in the subsequence is nested.\n isNested('[[]]') \u279e true\n isNested('[]]]]]]][[[[[]') \u279e false\n isNested('[][]') \u279e false\n isNested('[]') \u279e false\n isNested('[[][]]') \u279e true\n isNested('[[]][[') \u279e true\n */\nconst isNested = (string) => {\n", "canonical_solution": " let opening_bracket_index = []\n let closing_bracket_index1 = []\n for (let i = 0; i < string.length; i++) {\n if (string[i] == '[') {\n opening_bracket_index.push(i)\n }\n else {\n closing_bracket_index1.push(i)\n }\n }\n let closing_bracket_index = []\n for (let i = 0; i < closing_bracket_index1.length; i++) {\n closing_bracket_index.push(closing_bracket_index1[closing_bracket_index1.length - i - 1])\n }\n let cnt = 0\n let i = 0\n let l = closing_bracket_index.length\n for (let k = 0; k < opening_bracket_index.length; k++) {\n if (i < l && opening_bracket_index[k] < closing_bracket_index[i]) {\n cnt += 1;\n i += 1;\n }\n }\n return cnt >= 2\n}\n\n", "test": "const testIsNested = () => {\n console.assert(isNested('[[]]') === true)\n console.assert(isNested('[]]]]]]][[[[[]') === false)\n console.assert(isNested('[][]') === false)\n console.assert(isNested('[]') === false)\n console.assert(isNested('[[[[]]]]') === true)\n console.assert(isNested('[]]]]]]]]]]') === false)\n console.assert(isNested('[][][[]]') === true)\n console.assert(isNested('[[]') === false)\n console.assert(isNested('[]]') === false)\n console.assert(isNested('[[]][[') === true)\n console.assert(isNested('[[][]]') === true)\n console.assert(isNested('') === false)\n console.assert(isNested('[[[[[[[[') === false)\n console.assert(isNested(']]]]]]]]') === false)\n}\n\ntestIsNested()\n", "declaration": "\nconst isNested = (string) => {\n", "example_test": "const testIsNested = () => {\n console.assert(isNested('[[]]') === true)\n console.assert(isNested('[]]]]]]][[[[[]') === false)\n console.assert(isNested('[][]') === false)\n console.assert(isNested('[]') === false)\n console.assert(isNested('[[]][[') === true)\n console.assert(isNested('[[][]]') === true)\n}\ntestIsNested()\n", "buggy_solution": " let opening_bracket_index = []\n let closing_bracket_index1 = []\n for (let i = 0; i < string.length; i++) {\n if (string[i] == '(') {\n opening_bracket_index.push(i)\n }\n else {\n closing_bracket_index1.push(i)\n }\n }\n let closing_bracket_index = []\n for (let i = 0; i < closing_bracket_index1.length; i++) {\n closing_bracket_index.push(closing_bracket_index1[closing_bracket_index1.length - i - 1])\n }\n let cnt = 0\n let i = 0\n let l = closing_bracket_index.length\n for (let k = 0; k < opening_bracket_index.length; k++) {\n if (i < l && opening_bracket_index[k] < closing_bracket_index[i]) {\n cnt += 1;\n i += 1;\n }\n }\n return cnt >= 2\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "isNested"} -{"task_id": "JavaScript/133", "prompt": "/*You are given a list of numbers.\n You need to return the sum of squared numbers in the given list,\n round each element in the list to the upper int(Ceiling) first.\n Examples:\n For lst = [1,2,3] the output should be 14\n For lst = [1,4,9] the output should be 98\n For lst = [1,3,5,7] the output should be 84\n For lst = [1.4,4.2,0] the output should be 29\n For lst = [-2.4,1,1] the output should be 6\n */\nconst sumSquares = (lst) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n let y = lst[i]\n if (y % 1 != 0) {\n if (y > 0) { y = y - y % 1 + 1 }\n else { y = -y; y = y - y % 1 }\n }\n p += y * y\n }\n return p\n}\n\n", "test": "const testSumSquares = () => {\n console.assert(sumSquares([1, 2, 3]) === 14)\n console.assert(sumSquares([1.0, 2, 3]) === 14)\n console.assert(sumSquares([1, 3, 5, 7]) === 84)\n console.assert(sumSquares([1.4, 4.2, 0]) === 29)\n console.assert(sumSquares([-2.4, 1, 1]) === 6)\n\n console.assert(sumSquares([100, 1, 15, 2]) === 10230)\n console.assert(sumSquares([10000, 10000]) === 200000000)\n console.assert(sumSquares([-1.4, 4.6, 6.3]) === 75)\n console.assert(sumSquares([-1.4, 17.9, 18.9, 19.9]) === 1086)\n\n console.assert(sumSquares([0]) === 0)\n console.assert(sumSquares([-1]) === 1)\n console.assert(sumSquares([-1, 1, 0]) === 2)\n}\n\ntestSumSquares()\n", "declaration": "\nconst sumSquares = (lst) => {\n", "example_test": "const testSumSquares = () => {\n console.assert(sumSquares([1, 2, 3]) === 14)\n console.assert(sumSquares([1, 4, 9]) === 98)\n console.assert(sumSquares([1, 3, 5, 7]) === 84)\n console.assert(sumSquares([1.4, 4.2, 0]) === 29)\n console.assert(sumSquares([-2.4, 1, 1]) === 6)\n}\ntestSumSquares()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n let y = lst[i]\n if (y % 1 != 0) {\n if (y > 0) { y = y - y % 1 + 1 }\n else { y = -y; y = y - y % 1 }\n }\n p += y * 2\n }\n return p\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "sumSquares"} -{"task_id": "JavaScript/134", "prompt": "/* Create a function that returns true if the last character\n of a given string is an alphabetical character and is not\n a part of a word, and false otherwise.\n Note: \"word\" is a group of characters separated by space.\n Examples:\n checkIfLastCharIsALetter(\"apple pie\") \u279e false\n checkIfLastCharIsALetter(\"apple pi e\") \u279e true\n checkIfLastCharIsALetter(\"apple pi e \") \u279e false\n checkIfLastCharIsALetter(\"\") \u279e false\n */\nconst checkIfLastCharIsALetter = (txt) => {\n", "canonical_solution": " let len = txt.length\n if (len == 0) { return false }\n let y = txt[len - 1].charCodeAt()\n if (len == 1) {\n if ((y >= 65 && y <= 90) || (y >= 97 && y <= 122)) { return true }\n return false\n }\n if (txt[len - 2] == ' ' && ((y >= 65 && y <= 90) || (y >= 97 && y <= 122))) { return true }\n return false\n}\n\n", "test": "const testCheckIfLastCharIsALetter = () => {\n console.assert(checkIfLastCharIsALetter('apple') === false)\n console.assert(checkIfLastCharIsALetter('apple pi e') === true)\n console.assert(checkIfLastCharIsALetter('eeeee') === false)\n console.assert(checkIfLastCharIsALetter('A') === true)\n console.assert(checkIfLastCharIsALetter('Pumpkin pie ') === false)\n console.assert(checkIfLastCharIsALetter('Pumpkin pie 1') === false)\n console.assert(checkIfLastCharIsALetter('') === false)\n console.assert(checkIfLastCharIsALetter('eeeee e ') === false)\n console.assert(checkIfLastCharIsALetter('apple pie') === false)\n console.assert(checkIfLastCharIsALetter('apple pi e ') === false)\n}\n\ntestCheckIfLastCharIsALetter()\n", "declaration": "\nconst checkIfLastCharIsALetter = (txt) => {\n", "example_test": "const testCheckIfLastCharIsALetter = () => {\n console.assert(checkIfLastCharIsALetter('apple pi e') === true)\n console.assert(checkIfLastCharIsALetter('') === false)\n console.assert(checkIfLastCharIsALetter('apple pie') === false)\n console.assert(checkIfLastCharIsALetter('apple pi e ') === false)\n}\ntestCheckIfLastCharIsALetter()\n", "buggy_solution": " let len = txt.length\n if (len == 0) { return false }\n let y = txt[len - 1].charCodeAt()\n if (len == 1) {\n if ((y >= 0 && y <= 22) || (y >= 30 && y <= 54)) { return true }\n return false\n }\n if (txt[len - 2] == ' ' && ((y >= 150 && y <= 200) || (y >= 250 && y <= 300))) { return true }\n return false\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "checkIfLastCharIsALetter"} -{"task_id": "JavaScript/135", "prompt": "/*Create a function which returns the largest index of an element which\n is not greater than or equal to the element immediately preceding it. If\n no such element exists then return -1. The given array will not contain\n duplicate values.\n\n Examples:\n canArrange([1,2,4,3,5]) = 3\n canArrange([1,2,3]) = -1\n */\nconst canArrange = (arr) => {\n", "canonical_solution": " if (arr.length == 0) { return -1 }\n for (let i = arr.length - 1; i > 0; i--) {\n if (arr[i] < arr[i - 1]) { return i }\n }\n return -1\n}\n\n", "test": "const testCanArrange = () => {\n console.assert(canArrange([1, 2, 4, 3, 5]) === 3)\n console.assert(canArrange([1, 2, 4, 5]) === -1)\n console.assert(canArrange([1, 4, 2, 5, 6, 7, 8, 9, 10]) === 2)\n console.assert(canArrange([4, 8, 5, 7, 3]) === 4)\n console.assert(canArrange([]) === -1)\n}\n\ntestCanArrange()\n", "declaration": "\nconst canArrange = (arr) => {\n", "example_test": "const testCanArrange = () => {\n console.assert(canArrange([1, 2, 4, 3, 5]) === 3)\n console.assert(canArrange([1, 2, 3]) === -1)\n}\ntestCanArrange()\n", "buggy_solution": " if (arr.length == 0) { return -1 }\n for (let i = arr.length - 1; i > 0; i--) {\n if (arr[i] < arr[i - 1]) { return i + arr[i] }\n }\n return -1\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "canArrange"} -{"task_id": "JavaScript/136", "prompt": "/* Create a function that returns a tuple (a, b), where 'a' is\n the largest of negative integers, and 'b' is the smallest\n of positive integers in a list.\n If there is no negative or positive integers, return them as null.\n Examples:\n largestSmallestIntegers([2, 4, 1, 3, 5, 7]) == (null, 1)\n largestSmallestIntegers([]) == (null, null)\n largestSmallestIntegers([0]) == (null, null)\n */\nconst largestSmallestIntegers = (lst) => {\n", "canonical_solution": " let a = Infinity\n let b = -Infinity\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] > 0 && lst[i] < a) { a = lst[i] }\n if (lst[i] < 0 && lst[i] > b) { b = lst[i] }\n }\n if (a == Infinity) { a = null }\n if (b == -Infinity) { b = null }\n return (b, a)\n}\n\n", "test": "const testLargestSmallestIntegers = () => {\n console.assert(\n JSON.stringify(largestSmallestIntegers([2, 4, 1, 3, 5, 7])) ===\n JSON.stringify((null, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([2, 4, 1, 3, 5, 7, 0])) ===\n JSON.stringify((null, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([1, 3, 2, 4, 5, 6, -2])) ===\n JSON.stringify((-2, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([4, 5, 3, 6, 2, 7, -7])) ===\n JSON.stringify((-7, 2))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([7, 3, 8, 4, 9, 2, 5, -9])) ===\n JSON.stringify((-9, 2))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([])) === JSON.stringify((null, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([0])) ===\n JSON.stringify((null, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-1, -3, -5, -6])) ===\n JSON.stringify((-1, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-1, -3, -5, -6, 0])) ===\n JSON.stringify((-1, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-6, -4, -4, -3, 1])) ===\n JSON.stringify((-3, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-6, -4, -4, -3, -100, 1])) ===\n JSON.stringify((-3, 1))\n )\n}\n\ntestLargestSmallestIntegers()\n", "declaration": "\nconst largestSmallestIntegers = (lst) => {\n", "example_test": "const testLargestSmallestIntegers = () => {\n console.assert(\n JSON.stringify(largestSmallestIntegers([2, 4, 1, 3, 5, 7])) ===\n JSON.stringify((null, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([])) === JSON.stringify((null, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([0])) ===\n JSON.stringify((null, null))\n )\n}\ntestLargestSmallestIntegers()\n", "buggy_solution": " let a = Infinity\n let b = -Infinity\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] > 0 && lst[i] < a) { a = lst[i] }\n if (lst[i] < 0 && lst[i] > b) { b = lst[i] }\n if (lst[i] < a) { b = a }\n if (lst[i] < b) { a = b }\n }\n if (a == Infinity) { a = null }\n if (b == -Infinity) { b = null }\n return (b, a)\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "largestSmallestIntegers"} -{"task_id": "JavaScript/137", "prompt": "/*\n Create a function that takes integers, floats, or strings representing\n real numbers, and returns the larger variable in its given variable type.\n Return null if the values are equal.\n Note: If a real number is represented as a string, the floating point might be . or ,\n\n compareOne(1, 2.5) \u279e 2.5\n compareOne(1, \"2,3\") \u279e \"2,3\"\n compareOne(\"5,1\", \"6\") \u279e \"6\"\n compareOne(\"1\", 1) \u279e null\n */\nconst compareOne = (a, b) => {\n", "canonical_solution": " let aa = Number(a)\n if (typeof a == 'string') { aa = Number(a.replace(',', '.')) }\n let bb = Number(b)\n if (typeof b == 'string') { bb = Number(b.replace(',', '.')) }\n if (aa > bb) { return a }\n if (aa < bb) { return b }\n return null\n}\n\n", "test": "const testCompareOne = () => {\n console.assert(compareOne(1, 2) === 2)\n console.assert(compareOne(1, 2.5) === 2.5)\n console.assert(compareOne(2, 3) === 3)\n console.assert(compareOne(5, 6) === 6)\n console.assert(compareOne(1, '2,3') === '2,3')\n console.assert(compareOne('5,1', '6') === '6')\n console.assert(compareOne('1', '2') === '2')\n console.assert(compareOne('1', 1) === null)\n}\n\ntestCompareOne()\n", "declaration": "\nconst compareOne = (a, b) => {\n", "example_test": "const testCompareOne = () => {\n console.assert(compareOne(1, 2.5) === 2.5)\n console.assert(compareOne(1, '2,3') === '2,3')\n console.assert(compareOne('5,1', '6') === '6')\n console.assert(compareOne('1', 1) === null)\n}\ntestCompareOne()\n", "buggy_solution": " let aa = Number(a)\n if (typeof a == 'string') { aa = Number(a.replace(',', '.').replace('.', ',')) }\n let bb = Number(b)\n if (typeof b == 'string') { bb = Number(b.replace(',', '.')) }\n if (aa > bb) { return a }\n if (aa < bb) { return b }\n return null\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "compareOne"} -{"task_id": "JavaScript/138", "prompt": "/*Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers\n Example\n isEqualToSumEven(4) == false\n isEqualToSumEven(6) == false\n isEqualToSumEven(8) == true\n */\nconst isEqualToSumEven = (n) => {\n", "canonical_solution": " return (n >= 8 && n % 2 == 0)\n}\n\n", "test": "const testIsEqualToSumEven = () => {\n console.assert(isEqualToSumEven(4) === false)\n console.assert(isEqualToSumEven(6) === false)\n console.assert(isEqualToSumEven(8) === true)\n console.assert(isEqualToSumEven(10) === true)\n console.assert(isEqualToSumEven(11) === false)\n console.assert(isEqualToSumEven(12) === true)\n console.assert(isEqualToSumEven(13) === false)\n console.assert(isEqualToSumEven(16) === true)\n}\n\ntestIsEqualToSumEven()\n", "declaration": "\nconst isEqualToSumEven = (n) => {\n", "example_test": "const testIsEqualToSumEven = () => {\n console.assert(isEqualToSumEven(4) === false)\n console.assert(isEqualToSumEven(6) === false)\n console.assert(isEqualToSumEven(8) === true)\n}\ntestIsEqualToSumEven()\n", "buggy_solution": " return (n >= 8 && n <= 8 && n % 2 == 0)\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "isEqualToSumEven"} -{"task_id": "JavaScript/139", "prompt": "/*The Brazilian factorial is defined as:\n brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\n where n > 0\n\n For example:\n >>> specialFactorial(4)\n 288\n\n The function will receive an integer as input and should return the special\n factorial of this integer.\n */\nconst specialFactorial = (n) => {\n", "canonical_solution": " let p = 1;\n let t = 1;\n while (n > 1) {\n let y = p;\n while (y > 0) {\n y--;\n t *= n;\n }\n p++;\n n--;\n }\n return t\n}\n\n", "test": "const testSpecialFactorial = () => {\n console.assert(specialFactorial(4) === 288)\n console.assert(specialFactorial(5) === 34560)\n console.assert(specialFactorial(7) === 125411328000)\n console.assert(specialFactorial(1) === 1)\n}\n\ntestSpecialFactorial()\n", "declaration": "\nconst specialFactorial = (n) => {\n", "example_test": "const testSpecialFactorial = () => {\n console.assert(specialFactorial(4) === 288)\n}\ntestSpecialFactorial()\n", "buggy_solution": " let p = 1;\n let t = 1;\n while (n > 1) {\n let y = p;\n while (y > 0) {\n y--;\n n *= y;\n t *= n;\n }\n p++;\n p++;\n n--;\n }\n return t\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "specialFactorial"} -{"task_id": "JavaScript/140", "prompt": "/*\n Given a string text, replace all spaces in it with underscores, \n and if a string has more than 2 consecutive spaces, \n then replace all consecutive spaces with - \n \n fixSpaces(\"Example\") == \"Example\"\n fixSpaces(\"Example 1\") == \"Example_1\"\n fixSpaces(\" Example 2\") == \"_Example_2\"\n fixSpaces(\" Example 3\") == \"_Example-3\"\n */\nconst fixSpaces = (text) => {\n", "canonical_solution": " let t = ''\n let c = 0\n for (let i = 0; i < text.length; i++) {\n if (text[i] == ' ') { c++ }\n else if (c > 0) {\n if (c == 1) { t += '_' }\n if (c == 2) { t += '__' }\n if (c > 2) { t += '-' }\n t += text[i]\n c = 0;\n } else {\n t += text[i]\n }\n }\n if (c == 1) { t += '_' }\n if (c == 2) { t += '__' }\n if (c > 2) { t += '-' }\n return t\n}\n\n", "test": "const testFixSpaces = () => {\n console.assert(fixSpaces('Example') === 'Example')\n console.assert(fixSpaces('Mudasir Hanif ') === 'Mudasir_Hanif_')\n console.assert(\n fixSpaces('Yellow Yellow Dirty Fellow') === 'Yellow_Yellow__Dirty__Fellow'\n )\n console.assert(fixSpaces('Exa mple') === 'Exa-mple')\n console.assert(fixSpaces(' Exa 1 2 2 mple') === '-Exa_1_2_2_mple')\n}\n\ntestFixSpaces()\n", "declaration": "\nconst fixSpaces = (text) => {\n", "example_test": "const testFixSpaces = () => {\n console.assert(fixSpaces('Example') === 'Example')\n console.assert(fixSpaces('Example 1') === 'Example_1')\n console.assert(\n fixSpaces(' Example 2') === '_Example_2'\n )\n console.assert(fixSpaces(' Example 3') === '_Example-3')\n}\ntestFixSpaces()\n", "buggy_solution": " let t = ''\n let c = 0\n for (let i = 0; i < text.length; i++) {\n if (text[i] == ' ') { c++ }\n else if (c > 0) {\n if (c == 1) { t += '_' }\n if (c == 2) { t += '___' }\n if (c > 2) { t += '--' }\n t += text[i]\n c = 0;\n } else {\n t += text[i]\n }\n }\n if (c == 1) { t += '__' }\n if (c == 2) { t += '___' }\n if (c > 2) { t += '-' }\n return t\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "fixSpaces"} -{"task_id": "JavaScript/141", "prompt": "/*Create a function which takes a string representing a file's name, and returns\n 'Yes' if the the file's name is valid, and returns 'No' otherwise.\n A file's name is considered to be valid if and only if all the following conditions \n are met:\n - There should not be more than three digits ('0'-'9') in the file's name.\n - The file's name contains exactly one dot '.'\n - The substring before the dot should not be empty, and it starts with a letter from \n the latin alphapet ('a'-'z' and 'A'-'Z').\n - The substring after the dot should be one of these: ['txt', 'exe', 'dll']\n Examples:\n fileNameCheck(\"example.txt\") # => 'Yes'\n fileNameCheck(\"1example.dll\") # => 'No' (the name should start with a latin alphapet letter)\n */\nconst fileNameCheck = (file_name) => {\n", "canonical_solution": " let t = file_name.split(/\\./)\n if (t.length != 2) { return 'No' }\n if (t[1] != 'txt' && t[1] != 'dll' && t[1] != 'exe') { return 'No' }\n if (t[0] == '') { return 'No' }\n let a = t[0][0].charCodeAt()\n if (!((a >= 65 && a <= 90) || (a >= 97 && a <= 122))) { return 'No' }\n let y = 0\n for (let i = 1; i < t[0].length; i++) {\n if (t[0][i].charCodeAt() >= 48 && t[0][i].charCodeAt() <= 57) { y++ }\n if (y > 3) { return 'No' }\n }\n return 'Yes'\n}\n\n", "test": "const testFileNameCheck = () => {\n console.assert(fileNameCheck('example.txt') === 'Yes')\n console.assert(fileNameCheck('1example.dll') === 'No')\n console.assert(fileNameCheck('s1sdf3.asd') === 'No')\n console.assert(fileNameCheck('K.dll') === 'Yes')\n console.assert(fileNameCheck('MY16FILE3.exe') === 'Yes')\n console.assert(fileNameCheck('His12FILE94.exe') === 'No')\n console.assert(fileNameCheck('_Y.txt') === 'No')\n console.assert(fileNameCheck('?aREYA.exe') === 'No')\n console.assert(fileNameCheck('/this_is_valid.dll') === 'No')\n console.assert(fileNameCheck('this_is_valid.wow') === 'No')\n console.assert(fileNameCheck('this_is_valid.txt') === 'Yes')\n console.assert(fileNameCheck('this_is_valid.txtexe') === 'No')\n console.assert(fileNameCheck('#this2_i4s_5valid.ten') === 'No')\n console.assert(fileNameCheck('@this1_is6_valid.exe') === 'No')\n console.assert(fileNameCheck('this_is_12valid.6exe4.txt') === 'No')\n console.assert(fileNameCheck('all.exe.txt') === 'No')\n console.assert(fileNameCheck('I563_No.exe') === 'Yes')\n console.assert(fileNameCheck('Is3youfault.txt') === 'Yes')\n console.assert(fileNameCheck('no_one#knows.dll') === 'Yes')\n console.assert(fileNameCheck('1I563_Yes3.exe') === 'No')\n console.assert(fileNameCheck('I563_Yes3.txtt') === 'No')\n console.assert(fileNameCheck('final..txt') === 'No')\n console.assert(fileNameCheck('final132') === 'No')\n console.assert(fileNameCheck('_f4indsartal132.') === 'No')\n console.assert(fileNameCheck('.txt') === 'No')\n console.assert(fileNameCheck('s.') === 'No')\n}\n\ntestFileNameCheck()\n", "declaration": "\nconst fileNameCheck = (file_name) => {\n", "example_test": "const testFileNameCheck = () => {\n console.assert(fileNameCheck('example.txt') === 'Yes')\n console.assert(fileNameCheck('1example.dll') === 'No')\n}\ntestFileNameCheck()\n", "buggy_solution": " let t = file_name.split(/\\./)\n if (t.length != 2) { return 'No' }\n if (t[0] == '') { return 'No' }\n let a = t[0][0].charCodeAt()\n if (!((a >= 65 && a <= 90) || (a >= 97 && a <= 122))) { return 'No' }\n let y = 0\n for (let i = 1; i < t[0].length; i++) {\n if (t[0][i].charCodeAt() >= 48 && t[0][i].charCodeAt() <= 57) { y++ }\n if (y > 3) { return 'No' }\n }\n return 'Yes'\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "fileNameCheck"} -{"task_id": "JavaScript/142", "prompt": "/*\"\n This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a \n multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not \n change the entries in the list whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries. \n \n Examples:\n For lst = [1,2,3] the output should be 6\n For lst = [] the output should be 0\n For lst = [-1,-5,2,-1,-5] the output should be -126\n */\nconst sumSquares = (lst) => {\n", "canonical_solution": " let y = 0\n for (let i = 0; i < lst.length; i++) {\n if (i % 3 == 0) { y += lst[i] * lst[i] }\n else if (i % 4 == 0) { y += lst[i] * lst[i] * lst[i] }\n else { y += lst[i] }\n }\n return y\n}\n\n", "test": "const testSumSquares = () => {\n console.assert(sumSquares([1, 2, 3]) === 6)\n console.assert(sumSquares([1, 4, 9]) === 14)\n console.assert(sumSquares([]) === 0)\n console.assert(sumSquares([1, 1, 1, 1, 1, 1, 1, 1, 1]) === 9)\n console.assert(sumSquares([-1, -1, -1, -1, -1, -1, -1, -1, -1]) === -3)\n console.assert(sumSquares([0]) === 0)\n console.assert(sumSquares([-1, -5, 2, -1, -5]) === -126)\n console.assert(sumSquares([-56, -99, 1, 0, -2]) === 3030)\n console.assert(sumSquares([-1, 0, 0, 0, 0, 0, 0, 0, -1]) === 0)\n console.assert(\n sumSquares([\n -16, -9, -2, 36, 36, 26, -20, 25, -40, 20, -4, 12, -26, 35, 37,\n ]) === -14196\n )\n console.assert(\n sumSquares([\n -1, -3, 17, -1, -15, 13, -1, 14, -14, -12, -5, 14, -14, 6, 13, 11, 16, 16,\n 4, 10,\n ]) === -1448\n )\n}\n\ntestSumSquares()\n", "declaration": "\nconst sumSquares = (lst) => {\n", "example_test": "const testSumSquares = () => {\n console.assert(sumSquares([1, 2, 3]) === 6)\n console.assert(sumSquares([]) === 0)\n console.assert(sumSquares([-1, -5, 2, -1, -5]) === -126)\n}\ntestSumSquares()\n", "buggy_solution": " let y = 0\n for (let i = 0; i < lst.length; i++) {\n if (i % 3 == 0) { y += lst[i] * lst[i] }\n else { y += lst[i] }\n }\n return y\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sumSquares"} -{"task_id": "JavaScript/143", "prompt": "/*\n You are given a string representing a sentence,\n the sentence contains some words separated by a space,\n and you have to return a string that contains the words from the original sentence,\n whose lengths are prime numbers,\n the order of the words in the new string should be the same as the original one.\n\n Example 1:\n Input: sentence = \"This is a test\"\n Output: \"is\"\n\n Example 2:\n Input: sentence = \"lets go for swimming\"\n Output: \"go for\"\n\n Constraints:\n * 1 <= len(sentence) <= 100\n * sentence contains only letters\n */\nconst wordsInSentence = (sentence) => {\n", "canonical_solution": " let t = sentence.split(/\\s/)\n let p = ''\n for (let j = 0; j < t.length; j++) {\n let len = t[j].length;\n let u = 1\n if (len == 1 || len == 0) { continue }\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { u = 0 }\n }\n if (u == 0) { continue }\n if (p == '') { p += t[j] }\n else { p = p + ' ' + t[j] }\n }\n return p\n}\n\n", "test": "const testWordsInSentence = () => {\n console.assert(wordsInSentence('This is a test') === 'is')\n console.assert(wordsInSentence('lets go for swimming') === 'go for')\n console.assert(\n wordsInSentence('there is no place available here') === 'there is no place'\n )\n console.assert(wordsInSentence('Hi I am Hussein') === 'Hi am Hussein')\n console.assert(wordsInSentence('go for it') === 'go for it')\n console.assert(wordsInSentence('here') === '')\n console.assert(wordsInSentence('here is') === 'is')\n}\n\ntestWordsInSentence()\n", "declaration": "\nconst wordsInSentence = (sentence) => {\n", "example_test": "const testWordsInSentence = () => {\n console.assert(wordsInSentence('This is a test') === 'is')\n console.assert(wordsInSentence('lets go for swimming') === 'go for')\n}\ntestWordsInSentence()\n", "buggy_solution": " let t = sentence.split(/\\s/)\n let p = ''\n for (let j = 0; j < t.length; j++) {\n let len = t[j].length;\n let u = 1\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { u = 0 }\n }\n if (u == 0) { continue }\n if (p == '') { p += t[j] }\n else { p = p + ' ' + t[j] }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "wordsInSentence"} -{"task_id": "JavaScript/144", "prompt": "/*Your task is to implement a function that will simplify the expression\n x * n. The function returns true if x * n evaluates to a whole number and false\n otherwise. Both x and n, are string representation of a fraction, and have the following format,\n / where both numerator and denominator are positive whole numbers.\n\n You can assume that x, and n are valid fractions, and do not have zero as denominator.\n\n simplify(\"1/5\", \"5/1\") = true\n simplify(\"1/6\", \"2/1\") = false\n simplify(\"7/10\", \"10/2\") = false\n */\nconst simplify = (x, n) => {\n", "canonical_solution": " let a = x.split(/\\//)\n let b = n.split(/\\//)\n let m = Number(a[0]) * Number(b[0])\n let r = Number(a[1]) * Number(b[1])\n return m % r == 0\n}\n\n", "test": "const testSimplify = () => {\n console.assert(simplify('1/5', '5/1') === true)\n console.assert(simplify('1/6', '2/1') === false)\n console.assert(simplify('5/1', '3/1') === true)\n console.assert(simplify('7/10', '10/2') === false)\n console.assert(simplify('2/10', '50/10') === true)\n console.assert(simplify('7/2', '4/2') === true)\n console.assert(simplify('11/6', '6/1') === true)\n console.assert(simplify('2/3', '5/2') === false)\n console.assert(simplify('5/2', '3/5') === false)\n console.assert(simplify('2/4', '8/4') === true)\n console.assert(simplify('2/4', '4/2') === true)\n console.assert(simplify('1/5', '5/1') === true)\n console.assert(simplify('1/5', '1/5') === false)\n}\n\ntestSimplify()\n", "declaration": "\nconst simplify = (x, n) => {\n", "example_test": "const testSimplify = () => {\n console.assert(simplify('1/5', '5/1') === true)\n console.assert(simplify('1/6', '2/1') === false)\n console.assert(simplify('7/10', '10/2') === false)\n}\ntestSimplify()\n", "buggy_solution": " let a = x.split(/\\//)\n let b = n.split(/\\//)\n let m = r * Number(a[0]) * Number(b[0])\n let r = m * Number(a[1]) * Number(b[1])\n let m = r * Number(a[1])\n let r = m * Number(b[1])\n return m % r == 0\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "simplify"} -{"task_id": "JavaScript/145", "prompt": "/*\n Write a function which sorts the given list of integers\n in ascending order according to the sum of their digits.\n Note: if there are several items with similar sum of their digits,\n order them based on their index in original list.\n\n For example:\n >>> orderByPoints([1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]\n >>> orderByPoints([]) == []\n */\nconst orderByPoints = (nums) => {\n", "canonical_solution": " let p = nums\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let m = 0\n let n = 0\n let h = p[k]\n let d = p[k + 1]\n let y = 1\n let u = 1\n if (h < 0) { y = -1; h = -h; }\n if (d < 0) { u = -1; d = -d; }\n while (h >= 10) {\n m += h % 10;\n h = (h - h % 10) / 10;\n }\n m += y * h\n while (d >= 10) {\n n += d % 10;\n d = (d - d % 10) / 10;\n }\n n += u * d\n if (m > n) {\n let tmp = p[k]\n p[k] = p[k + 1]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "test": "const testOrderByPoints = () => {\n console.assert(\n JSON.stringify(orderByPoints([1, 11, -1, -11, -12])) ===\n JSON.stringify([-1, -11, 1, -12, 11])\n )\n console.assert(\n JSON.stringify(\n orderByPoints([\n 1234, 423, 463, 145, 2, 423, 423, 53, 6, 37, 3457, 3, 56, 0, 46,\n ])\n ) ===\n JSON.stringify([\n 0, 2, 3, 6, 53, 423, 423, 423, 1234, 145, 37, 46, 56, 463, 3457,\n ])\n )\n console.assert(JSON.stringify(orderByPoints([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(orderByPoints([1, -11, -32, 43, 54, -98, 2, -3])) ===\n JSON.stringify([-3, -32, -98, -11, 1, 2, 43, 54])\n )\n console.assert(\n JSON.stringify(orderByPoints([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])) ===\n JSON.stringify([1, 10, 2, 11, 3, 4, 5, 6, 7, 8, 9])\n )\n console.assert(\n JSON.stringify(orderByPoints([0, 6, 6, -76, -21, 23, 4])) ===\n JSON.stringify([-76, -21, 0, 4, 23, 6, 6])\n )\n}\n\ntestOrderByPoints()\n", "declaration": "\nconst orderByPoints = (nums) => {\n", "example_test": "const testOrderByPoints = () => {\n console.assert(\n JSON.stringify(orderByPoints([1, 11, -1, -11, -12])) ===\n JSON.stringify([-1, -11, 1, -12, 11])\n )\n console.assert(JSON.stringify(orderByPoints([])) === JSON.stringify([]))\n}\ntestOrderByPoints()\n", "buggy_solution": " let p = nums\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let m = 0\n let n = 0\n let h = p[k]\n let d = p[k + 1]\n let y = 1\n let u = 1\n if (h < 0) { y = -1; h = -h; }\n if (d < 0) { u = -1; d = -d; }\n while (h >= 10) {\n m += h % 10;\n h = (h - h % 10) / 10;\n }\n m += y * h + h\n while (d >= 10) {\n n += d % 10;\n d = (d - d % 10) / 10;\n }\n n += u * d\n if (m > n) {\n let tmp = p[k]\n p[k] = p[k + 1]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "orderByPoints"} -{"task_id": "JavaScript/146", "prompt": "/*Write a function that takes an array of numbers as input and returns \n the number of elements in the array that are greater than 10 and both \n first and last digits of a number are odd (1, 3, 5, 7, 9).\n For example:\n specialFilter([15, -73, 14, -15]) => 1 \n specialFilter([33, -2, -3, 45, 21, 109]) => 2\n */\nconst specialFilter = (nums) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < nums.length; i++) {\n if (nums[i] < 10) { continue }\n let y = nums[i].toString()\n if (Number(y[0]) % 2 == 1 && Number(y[y.length - 1]) % 2 == 1) {\n p++\n }\n }\n return p\n}\n\n", "test": "const testSpecialFilter = () => {\n console.assert(specialFilter([5, -2, 1, -5]) === 0)\n console.assert(specialFilter([15, -73, 14, -15]) === 1)\n console.assert(specialFilter([33, -2, -3, 45, 21, 109]) === 2)\n console.assert(specialFilter([43, -12, 93, 125, 121, 109]) === 4)\n console.assert(specialFilter([71, -2, -33, 75, 21, 19]) === 3)\n console.assert(specialFilter([1]) === 0)\n console.assert(specialFilter([]) === 0)\n}\n\ntestSpecialFilter()\n", "declaration": "\nconst specialFilter = (nums) => {\n", "example_test": "const testSpecialFilter = () => {\n console.assert(specialFilter([15, -73, 14, -15]) === 1)\n console.assert(specialFilter([33, -2, -3, 45, 21, 109]) === 2)\n}\ntestSpecialFilter()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < nums.length; i++) {\n if (nums[i] < 10) { continue }\n let y = nums[i].toString()\n if (Number(y[0]) % 2 == 1 && Number(y[y.length - 1]) % 2 == 1 && Number(y[y.length - 1]) % 2 == 0) {\n p++\n }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "specialFilter"} -{"task_id": "JavaScript/147", "prompt": "/*\n You are given a positive integer n. You have to create an integer array a of length n.\n For each i (1 \u2264 i \u2264 n), the value of a[i] = i * i - i + 1.\n Return the number of triples (a[i], a[j], a[k]) of a where i < j < k, \n and a[i] + a[j] + a[k] is a multiple of 3.\n\n Example :\n Input: n = 5\n Output: 1\n Explanation: \n a = [1, 3, 7, 13, 21]\n The only valid triple is (1, 7, 13).\n */\nconst getMaxTriples = (n) => {\n", "canonical_solution": " let y = []\n for (let i = 1; i <= n; i++) {\n y.push(i * i - i + 1)\n }\n let u = 0\n for (let i = 0; i < n - 2; i++) {\n for (let j = i + 1; j < n - 1; j++) {\n for (let k = j + 1; k < n; k++) {\n if ((y[i] + y[j] + y[k]) % 3 == 0) { u++ }\n }\n }\n }\n return u\n}\n\n", "test": "const testGetMaxTriples = () => {\n console.assert(getMaxTriples(5) === 1)\n console.assert(getMaxTriples(6) === 4)\n console.assert(getMaxTriples(10) === 36)\n console.assert(getMaxTriples(100) === 53361)\n}\n\ntestGetMaxTriples()\n", "declaration": "\nconst getMaxTriples = (n) => {\n", "example_test": "const testGetMaxTriples = () => {\n console.assert(getMaxTriples(5) === 1)\n}\ntestGetMaxTriples()\n", "buggy_solution": " let y = []\n for (let i = 1; i <= n; i++) {\n y.push(i)\n }\n let u = 0\n for (let i = 0; i < n - 2; i++) {\n for (let j = i + 1; j < n - 1; j++) {\n for (let k = j + 1; k < n; k++) {\n if ((y[i] + y[j] + y[k]) % 3 == 0) { u++ }\n }\n }\n }\n return u\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "getMaxTriples"} -{"task_id": "JavaScript/148", "prompt": "/* There are eight planets in our solar system: the closerst to the Sun\n is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,\n Uranus, Neptune.\n Write a function that takes two planet names as strings planet1 and planet2.\n The function should return a tuple containing all planets whose orbits are\n located between the orbit of planet1 and the orbit of planet2, sorted by\n the proximity to the sun.\n The function should return an empty tuple if planet1 or planet2\n are not correct planet names.\n Examples\n bf(\"Jupiter\", \"Neptune\") ==> (\"Saturn\", \"Uranus\")\n bf(\"Earth\", \"Mercury\") ==> (\"Venus\")\n bf(\"Mercury\", \"Uranus\") ==> (\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\")\n */\nconst bf = (planet1, planet2) => {\n", "canonical_solution": " let y = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']\n let u = []\n let lo = -1\n let hi = -1\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet1) { lo = i }\n }\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet2) { hi = i }\n }\n if (lo == -1 || hi == -1 || lo == hi) { return [] }\n if (lo > hi) {\n let tmp = lo;\n lo = hi;\n hi = tmp;\n }\n for (let i = lo + 1; i < hi; i++) {\n u.push(y[i])\n }\n return u\n}\n\n", "test": "const testBf = () => {\n console.assert(\n JSON.stringify(bf('Jupiter', 'Neptune')) ===\n JSON.stringify(['Saturn', 'Uranus'])\n )\n console.assert(\n JSON.stringify(bf('Earth', 'Mercury')) === JSON.stringify(['Venus'])\n )\n console.assert(\n JSON.stringify(bf('Mercury', 'Uranus')) ===\n JSON.stringify(['Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn'])\n )\n console.assert(\n JSON.stringify(bf('Neptune', 'Venus')) ===\n JSON.stringify(['Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus'])\n )\n console.assert(JSON.stringify(bf('Earth', 'Earth')) === JSON.stringify([]))\n console.assert(JSON.stringify(bf('Mars', 'Earth')) === JSON.stringify([]))\n console.assert(\n JSON.stringify(bf('Jupiter', 'Makemake')) === JSON.stringify([])\n )\n}\n\ntestBf()\n", "declaration": "\nconst bf = (planet1, planet2) => {\n", "example_test": "const testBf = () => {\n console.assert(\n JSON.stringify(bf('Jupiter', 'Neptune')) ===\n JSON.stringify(['Saturn', 'Uranus'])\n )\n console.assert(\n JSON.stringify(bf('Earth', 'Mercury')) === JSON.stringify(['Venus'])\n )\n console.assert(\n JSON.stringify(bf('Mercury', 'Uranus')) ===\n JSON.stringify(['Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn'])\n )\n}\ntestBf()\n", "buggy_solution": " let y = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupyter', 'Saturn', 'Uranus', 'Neptune']\n let u = []\n let lo = -1\n let hi = -1\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet1) { lo = i }\n }\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet2) { hi = i }\n }\n if (lo == -1 || hi == -1 || lo == hi) { return [] }\n if (lo > hi) {\n let tmp = lo;\n lo = hi;\n hi = tmp;\n }\n for (let i = lo + 1; i < hi; i++) {\n u.push(y[i])\n }\n return u\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "bf"} -{"task_id": "JavaScript/149", "prompt": "/*Write a function that accepts a list of strings as a parameter,\n deletes the strings that have odd lengths from it,\n and returns the resulted list with a sorted order,\n The list is always a list of strings and never an array of numbers,\n and it may contain duplicates.\n The order of the list should be ascending by length of each word, and you\n should return the list sorted by that rule.\n If two words have the same length, sort the list alphabetically.\n The function should return a list of strings in sorted order.\n You may assume that all words will have the same length.\n For example:\n assert list_sort([\"aa\", \"a\", \"aaa\"]) => [\"aa\"]\n assert list_sort([\"ab\", \"a\", \"aaa\", \"cd\"]) => [\"ab\", \"cd\"]\n */\nconst sortedListSum = (lst) => {\n", "canonical_solution": " let p = []\n for (let i = 0; i < lst.length; i++) {\n if (lst[i].length % 2 == 0) {\n p.push(lst[i])\n }\n }\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let f = 0\n if (p[k].length > p[k + 1].length) { f = 1 }\n if (p[k].length == p[k + 1].length) {\n let r = p[k].length\n for (let l = 0; l < r; l++) {\n if (p[k][l].charCodeAt() > p[k + 1][l].charCodeAt()) {\n f = 1;\n break;\n }\n if (p[k][l].charCodeAt() < p[k + 1][l].charCodeAt()) {\n break;\n }\n }\n }\n if (f == 1) {\n let tmp = p[k]\n p[k] = p[k + 1]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "test": "const testSortedListSum = () => {\n console.assert(\n JSON.stringify(sortedListSum(['aa', 'a', 'aaa'])) === JSON.stringify(['aa'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['school', 'AI', 'asdf', 'b'])) ===\n JSON.stringify(['AI', 'asdf', 'school'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['d', 'b', 'c', 'a'])) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(sortedListSum(['d', 'dcba', 'abcd', 'a'])) ===\n JSON.stringify(['abcd', 'dcba'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['AI', 'ai', 'au'])) ===\n JSON.stringify(['AI', 'ai', 'au'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['a', 'b', 'b', 'c', 'c', 'a'])) ===\n JSON.stringify([])\n )\n console.assert(\n JSON.stringify(sortedListSum(['aaaa', 'bbbb', 'dd', 'cc'])) ===\n JSON.stringify(['cc', 'dd', 'aaaa', 'bbbb'])\n )\n}\n\ntestSortedListSum()\n", "declaration": "\nconst sortedListSum = (lst) => {\n", "example_test": "const testSortedListSum = () => {\n console.assert(\n JSON.stringify(sortedListSum(['aa', 'a', 'aaa'])) === JSON.stringify(['aa'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['ab', 'a', 'aaa', 'cd'])) ===\n JSON.stringify(['ab', 'cd'])\n )\n}\ntestSortedListSum()\n", "buggy_solution": " let p = []\n for (let i = 0; i < lst.length; i++) {\n if (lst[i].length % 2 == 0) {\n p.push(lst[i])\n }\n }\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let f = 0\n if (p[k].length > p[k + 1].length) { f = 1 }\n if (p[k].length == p[k + 1].length) {\n let r = p[k].length\n for (let l = 0; l < r; l++) {\n if (p[k][l].charCodeAt() > p[k + 1][l].charCodeAt()) {\n f = 1;\n break;\n }\n if (p[k][l].charCodeAt() < p[k + 1][l].charCodeAt()) {\n break;\n }\n }\n }\n if (f == 1) {\n let tmp = p[k]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sortedListSum"} -{"task_id": "JavaScript/150", "prompt": "/*A simple program which should return the value of x if n is \n a prime number and should return the value of y otherwise.\n\n Examples:\n for xOrY(7, 34, 12) == 34\n for xOrY(15, 8, 5) == 5\n \n */\nconst xOrY = (n, x, y) => {\n", "canonical_solution": " let len = n\n if (len == 1 || len == 0) { return y }\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { return y }\n }\n return x\n}\n\n", "test": "const testXOrY = () => {\n console.assert(xOrY(7, 34, 12) === 34)\n console.assert(xOrY(15, 8, 5) === 5)\n console.assert(xOrY(3, 33, 5212) === 33)\n console.assert(xOrY(1259, 3, 52) === 3)\n console.assert(xOrY(7919, -1, 12) === -1)\n console.assert(xOrY(3609, 1245, 583) === 583)\n console.assert(xOrY(91, 56, 129) === 129)\n console.assert(xOrY(6, 34, 1234) === 1234)\n console.assert(xOrY(1, 2, 0) === 0)\n console.assert(xOrY(2, 2, 0) === 2)\n}\n\ntestXOrY()\n", "declaration": "\nconst xOrY = (n, x, y) => {\n", "example_test": "const testXOrY = () => {\n console.assert(xOrY(7, 34, 12) === 34)\n console.assert(xOrY(15, 8, 5) === 5)\n}\ntestXOrY()\n", "buggy_solution": " let len = n\n if (len == 1 || len == 0) { return y }\n for (let i = 2; i * i <= len; i++) {\n if (len % i - 1 == 0) { return y }\n }\n return x\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "xOrY"} -{"task_id": "JavaScript/151", "prompt": "/* Given a list of numbers, return the sum of squares of the numbers\n in the list that are odd. Ignore numbers that are negative or not integers.\n doubleTheDifference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10\n doubleTheDifference([-1, -2, 0]) == 0\n doubleTheDifference([9, -2]) == 81\n doubleTheDifference([0]) == 0\n If the input list is empty, return 0.\n */\nconst doubleTheDifference = (lst) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] % 2 == 1 && lst[i] > 0) {\n p += lst[i] * lst[i]\n }\n }\n return p\n}\n\n", "test": "const testDoubleTheDifference = () => {\n console.assert(doubleTheDifference([]) === 0)\n console.assert(doubleTheDifference([5, 4]) === 25)\n console.assert(doubleTheDifference([0.1, 0.2, 0.3]) === 0)\n console.assert(doubleTheDifference([-10, -20, -30]) === 0)\n console.assert(doubleTheDifference([-1, -2, 8]) === 0)\n console.assert(doubleTheDifference([0.2, 3, 5]) === 34)\n let lst = []\n let odd_sum = 0\n for (let i = -99; i < 100; i += 2) {\n if (i % 2 != 0 && i > 0) { odd_sum += i * i }\n lst.push(i)\n }\n console.assert(doubleTheDifference(lst) === odd_sum)\n}\ntestDoubleTheDifference()\n", "declaration": "\nconst doubleTheDifference = (lst) => {\n", "example_test": "const testDoubleTheDifference = () => {\n console.assert(doubleTheDifference([1,3,2,0]) === 10)\n console.assert(doubleTheDifference([-1,-2,0]) === 0)\n console.assert(doubleTheDifference([9,-2]) === 81)\n console.assert(doubleTheDifference([0]) === 0)\n}\ntestDoubleTheDifference()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] > 0) {\n p += lst[i]\n }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "doubleTheDifference"} -{"task_id": "JavaScript/152", "prompt": "/*I think we all remember that feeling when the result of some long-awaited\n event is finally known. The feelings and thoughts you have at that moment are\n definitely worth noting down and comparing.\n Your task is to determine if a person correctly guessed the results of a number of matches.\n You are given two arrays of scores and guesses of equal length, where each index shows a match. \n Return an array of the same length denoting how far off each guess was. If they have guessed correctly,\n the value is 0, and if not, the value is the absolute difference between the guess and the score.\n \n \n example:\n\n compare([1,2,3,4,5,1],[1,2,3,4,2,-2]) -> [0,0,0,0,3,3]\n compare([0,5,0,0,0,4],[4,1,1,0,0,-2]) -> [4,4,1,0,0,6]\n */\nconst compare = (game, guess) => {\n", "canonical_solution": " for (let i = 0; i < guess.length; i++) {\n game[i] -= guess[i]\n if (game[i]<0)\n game[i]=-game[i]; }\n return game\n}\n\n", "test": "const testCompare = () => {\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0,5,0,0,0,4],[4,1,1,0,0,-2])) ===\n JSON.stringify([4,4,1,0,0,6])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0])) ===\n JSON.stringify([0, 0, 0, 0, 0, 0])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3], [-1, -2, -3])) ===\n JSON.stringify([2, 4, 6])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3, 5], [-1, 2, 3, 4])) ===\n JSON.stringify([2, 0, 0, 1])\n )\n}\n\ntestCompare()\n", "declaration": "\nconst compare = (game, guess) => {\n", "example_test": "const testCompare = () => {\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0,5,0,0,0,4],[4,1,1,0,0,-2])) ===\n JSON.stringify([4,4,1,0,0,6])\n )\n}\ntestCompare()\n", "buggy_solution": " for (let i = 0; i < guess.length; i++) {\n game[i] -= guess[i]\n if (game[i]<0)\n game[i]=-game[i];\n if (guess[i]!=0)\n game[i]-=guess[i]; }\n return game\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "compare"} -{"task_id": "JavaScript/153", "prompt": "/*You will be given the name of a class (a string) and a list of extensions.\n The extensions are to be used to load additional classes to the class. The\n strength of the extension is as follows: Let CAP be the number of the uppercase\n letters in the extension's name, and let SM be the number of lowercase letters\n in the extension's name, the strength is given by the fraction CAP - SM.\n You should find the strongest extension and return a string in this\n format: ClassName.StrongestExtensionName.\n If there are two or more extensions with the same strength, you should\n choose the one that comes first in the list.\n For example, if you are given \"Slices\" as the class and a list of the\n extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should\n return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension\n (its strength is -1).\n Example:\n for strongestExtension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA'\n */\nconst strongestExtension = (class_name, extensions) => {\n", "canonical_solution": " let u = 0\n let s = -Infinity\n for (let i = extensions.length - 1; i >= 0; i--) {\n let y = 0\n for (let j = 0; j < extensions[i].length; j++) {\n let k = extensions[i][j].charCodeAt()\n if (k >= 65 && k <= 90) { y += 1 }\n if (k >= 97 && k <= 122) { y -= 1 }\n }\n if (y >= s) {\n s = y;\n u = i;\n }\n }\n return class_name + '.' + extensions[u]\n}\n\n", "test": "const testStrongestExtension = () => {\n console.assert(\n strongestExtension('Watashi', ['tEN', 'niNE', 'eIGHt8OKe']) ===\n 'Watashi.eIGHt8OKe'\n )\n console.assert(\n strongestExtension('Boku123', [\n 'nani',\n 'NazeDa',\n 'YEs.WeCaNe',\n '32145tggg',\n ]) === 'Boku123.YEs.WeCaNe'\n )\n console.assert(\n strongestExtension('__YESIMHERE', [\n 't',\n 'eMptY',\n 'nothing',\n 'zeR00',\n 'NuLl__',\n '123NoooneB321',\n ]) === '__YESIMHERE.NuLl__'\n )\n console.assert(\n strongestExtension('K', ['Ta', 'TAR', 't234An', 'cosSo']) === 'K.TAR'\n )\n console.assert(\n strongestExtension('__HAHA', ['Tab', '123', '781345', '-_-']) ===\n '__HAHA.123'\n )\n console.assert(\n strongestExtension('YameRore', [\n 'HhAas',\n 'okIWILL123',\n 'WorkOut',\n 'Fails',\n '-_-',\n ]) === 'YameRore.okIWILL123'\n )\n console.assert(\n strongestExtension('finNNalLLly', ['Die', 'NowW', 'Wow', 'WoW']) ===\n 'finNNalLLly.WoW'\n )\n console.assert(strongestExtension('_', ['Bb', '91245']) === '_.Bb')\n console.assert(strongestExtension('Sp', ['671235', 'Bb']) === 'Sp.671235')\n}\n\ntestStrongestExtension()\n", "declaration": "\nconst strongestExtension = (class_name, extensions) => {\n", "example_test": "const testStrongestExtension = () => {\n console.assert(\n strongestExtension('my_class', ['AA', 'Be', 'CC']) ===\n 'my_class.AA'\n )\n}\ntestStrongestExtension()\n", "buggy_solution": " let u = 0\n let s = -Infinity\n for (let i = extensions.length - 1; i >= 0; i--) {\n let y = 0\n for (let j = 0; j < extensions[i].length; j++) {\n let k = extensions[i][j].charCodeAt()\n if (k >= 65 && k <= 90) { y += 1 }\n if (k >= 97 && k <= 122) { y -= 1 }\n }\n if (y >= s) {\n s = y;\n u = i;\n }\n }\n return class_name + extensions[u]\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "strongestExtension"} -{"task_id": "JavaScript/154", "prompt": "/*You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word\n cycpatternCheck(\"abcd\",\"abd\") => false\n cycpatternCheck(\"hello\",\"ell\") => true\n cycpatternCheck(\"whassup\",\"psus\") => false\n cycpatternCheck(\"abab\",\"baa\") => true\n cycpatternCheck(\"efef\",\"eeff\") => false\n cycpatternCheck(\"himenss\",\"simen\") => true\n */\nconst cycpatternCheck = (a, b) => {\n", "canonical_solution": " let l = b.length\n let pat = b + b\n for (let i = 0; i < a.length - l + 1; i++) {\n for (let j = 0; j < l + 1; j++) {\n let y = 1\n for (let k = 0; k < l; k++) {\n if (a[i + k] != pat[j + k]) { y = 0 }\n }\n if (y == 1) {\n return true\n }\n }\n }\n return false\n}\n\n", "test": "const testCycpatternCheck = () => {\n console.assert(cycpatternCheck('xyzw', 'xyw') === false)\n console.assert(cycpatternCheck('yello', 'ell') === true)\n console.assert(cycpatternCheck('whattup', 'ptut') === false)\n console.assert(cycpatternCheck('efef', 'fee') === true)\n console.assert(cycpatternCheck('abab', 'aabb') === false)\n console.assert(cycpatternCheck('winemtt', 'tinem') === true)\n}\n\ntestCycpatternCheck()\n", "declaration": "\nconst cycpatternCheck = (a, b) => {\n", "example_test": "const testCycpatternCheck = () => {\n console.assert(cycpatternCheck('abcd', 'abd') === false)\n console.assert(cycpatternCheck('hello', 'ell') === true)\n console.assert(cycpatternCheck('whassup', 'psus') === false)\n console.assert(cycpatternCheck('abab', 'baa') === true)\n console.assert(cycpatternCheck('efef', 'eeff') === false)\n console.assert(cycpatternCheck('himenss', 'simen') === true)\n}\ntestCycpatternCheck()\n", "buggy_solution": " let l = b.length\n let pat = b + b\n for (let i = 0; i < a.length - l + 1; i++) {\n for (let j = 0; j < b.length - l + 1; j++) {\n let y = 1\n for (let k = 0; k < l; k++) {\n if (a[i + k] != pat[j + k]) { y = 0 }\n }\n if (y == 1) {\n return true\n }\n }\n }\n return false\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "cycpatternCheck"} -{"task_id": "JavaScript/155", "prompt": "/*Given an integer. return a tuple that has the number of even and odd digits respectively.\n\n Example:\n evenOddCount(-12) ==> (1, 1)\n evenOddCount(123) ==> (1, 2)\n */\nconst evenOddCount = (num) => {\n", "canonical_solution": " let o = 0\n let e = 0\n if (num < 0) { num = -num }\n while (num > 0) {\n if (num % 2 == 0) { e++ }\n else { o++ }\n num = (num - num % 10) / 10\n }\n return (e, o)\n}\n\n", "test": "const testEvenOddCount = () => {\n console.assert(JSON.stringify(evenOddCount(7)) === JSON.stringify((0, 1)))\n console.assert(JSON.stringify(evenOddCount(-78)) === JSON.stringify((1, 1)))\n console.assert(JSON.stringify(evenOddCount(3452)) === JSON.stringify((2, 2)))\n console.assert(\n JSON.stringify(evenOddCount(346211)) === JSON.stringify((3, 3))\n )\n console.assert(\n JSON.stringify(evenOddCount(-345821)) === JSON.stringify((3, 3))\n )\n console.assert(JSON.stringify(evenOddCount(-2)) === JSON.stringify((1, 0)))\n console.assert(\n JSON.stringify(evenOddCount(-45347)) === JSON.stringify((2, 3))\n )\n console.assert(JSON.stringify(evenOddCount(0)) === JSON.stringify((1, 0)))\n}\n\ntestEvenOddCount()\n", "declaration": "\nconst evenOddCount = (num) => {\n", "example_test": "const testEvenOddCount = () => {\n console.assert(JSON.stringify(evenOddCount(-12)) === JSON.stringify((1, 1)))\n console.assert(JSON.stringify(evenOddCount(123)) === JSON.stringify((1, 2)))\n}\ntestEvenOddCount()\n", "buggy_solution": " let o = 0\n let e = 0\n if (num < 0) { num = -num }\n while (num > 0) {\n if (num % 2 == 0) { e++ }\n else { o++ }\n num = num - num % 10\n }\n return (e, o)\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "evenOddCount"} -{"task_id": "JavaScript/156", "prompt": "/*\n Given a positive integer, obtain its roman numeral equivalent as a string,\n and return it in lowercase.\n Restrictions: 1 <= num <= 1000\n\n Examples:\n >>> intToMiniRoman(19) == 'xix'\n >>> intToMiniRoman(152) == 'clii'\n >>> intToMiniRoman(426) == 'cdxxvi'\n */\nconst intToMiniRoman = (number) => {\n", "canonical_solution": " let num = [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000]\n let sym = ['i', 'iv', 'v', 'ix', 'x', 'xl', 'l', 'xc', 'c', 'cd', 'd', 'cm', 'm']\n let i = 12\n let res = ''\n while (number) {\n let div = (number - number % num[i]) / num[i]\n number = number % num[i]\n while (div) {\n res += sym[i]\n div -= 1\n }\n i -= 1\n }\n return res\n}\n\n", "test": "const testIntToMiniRoman = () => {\n console.assert(intToMiniRoman(19) === 'xix')\n console.assert(intToMiniRoman(152) === 'clii')\n console.assert(intToMiniRoman(251) === 'ccli')\n console.assert(intToMiniRoman(426) === 'cdxxvi')\n console.assert(intToMiniRoman(500) === 'd')\n console.assert(intToMiniRoman(1) === 'i')\n console.assert(intToMiniRoman(4) === 'iv')\n console.assert(intToMiniRoman(43) === 'xliii')\n console.assert(intToMiniRoman(90) === 'xc')\n console.assert(intToMiniRoman(94) === 'xciv')\n console.assert(intToMiniRoman(532) === 'dxxxii')\n console.assert(intToMiniRoman(900) === 'cm')\n console.assert(intToMiniRoman(994) === 'cmxciv')\n console.assert(intToMiniRoman(1000) === 'm')\n}\n\ntestIntToMiniRoman()\n", "declaration": "\nconst intToMiniRoman = (number) => {\n", "example_test": "const testIntToMiniRoman = () => {\n console.assert(intToMiniRoman(19) === 'xix')\n console.assert(intToMiniRoman(152) === 'clii')\n console.assert(intToMiniRoman(426) === 'cdxxvi')\n}\ntestIntToMiniRoman()\n", "buggy_solution": " let num = [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000]\n let sym = ['i', 'iv', 'v', 'ix', 'x', 'xl', 'l', 'xc', 'c', 'cd', 'd', 'cm', 'm']\n let i = 12\n let res = ''\n while (number) {\n let div = (number - number % num[i]) / num[i]\n while (div) {\n res += sym[i]\n div -= 1\n }\n i -= 1\n }\n return res\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "infinite loop", "entry_point": "intToMiniRoman"} -{"task_id": "JavaScript/157", "prompt": "/*\n Given the lengths of the three sides of a triangle. Return true if the three\n sides form a right-angled triangle, false otherwise.\n A right-angled triangle is a triangle in which one angle is right angle or\n 90 degree.\n Example:\n rightAngleTriangle(3, 4, 5) == true\n rightAngleTriangle(1, 2, 3) == false\n */\nconst rightAngleTriangle = (a, b, c) => {\n", "canonical_solution": " return (a * a + b * b == c * c || a * a == b * b + c * c || b * b == a * a + c * c)\n}\n\n", "test": "const testRightAngleTriangle = () => {\n console.assert(rightAngleTriangle(3, 4, 5) === true)\n console.assert(rightAngleTriangle(1, 2, 3) === false)\n console.assert(rightAngleTriangle(10, 6, 8) === true)\n console.assert(rightAngleTriangle(2, 2, 2) === false)\n console.assert(rightAngleTriangle(7, 24, 25) === true)\n console.assert(rightAngleTriangle(10, 5, 7) === false)\n console.assert(rightAngleTriangle(5, 12, 13) === true)\n console.assert(rightAngleTriangle(15, 8, 17) === true)\n console.assert(rightAngleTriangle(48, 55, 73) === true)\n console.assert(rightAngleTriangle(1, 1, 1) === false)\n console.assert(rightAngleTriangle(2, 2, 10) === false)\n}\n\ntestRightAngleTriangle()\n", "declaration": "\nconst rightAngleTriangle = (a, b, c) => {\n", "example_test": "const testRightAngleTriangle = () => {\n console.assert(rightAngleTriangle(3, 4, 5) === true)\n console.assert(rightAngleTriangle(1, 2, 3) === false)\n}\ntestRightAngleTriangle()\n", "buggy_solution": " return (a * a + b * b == c * c)\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "rightAngleTriangle"} -{"task_id": "JavaScript/158", "prompt": "/*Write a function that accepts a list of strings.\n The list contains different words. Return the word with maximum number\n of unique characters. If multiple strings have maximum number of unique\n characters, return the one which comes first in lexicographical order.\n\n findMax([\"name\", \"of\", \"string\"]) === \"string\"\n findMax([\"name\", \"enam\", \"game\"]) === \"enam\"\n findMax([\"aaaaaaa\", \"bb\" ,\"cc\"]) === \"\"aaaaaaa\"\n */\nconst findMax = (words) => {\n", "canonical_solution": " let s = -1\n let u = -1\n if (words.length == 0) { return '' }\n for (let i = 0; i < words.length; i++) {\n let p = 0\n for (let j = 0; j < words[i].length; j++) {\n let y = 1\n for (let k = 0; k < j; k++) {\n if (words[i][j] == words[i][k]) { y = 0 }\n }\n if (y == 1) { p++ }\n }\n if (p > s || (p == s && words[i] < words[u])) {\n u = i;\n s = p;\n }\n }\n return words[u]\n}\n\n", "test": "const testFindMax = () => {\n console.assert(findMax(['name', 'of', 'string']) === 'string')\n console.assert(findMax(['name', 'enam', 'game']) === 'enam')\n console.assert(findMax(['aaaaaaa', 'bb', 'cc']) === 'aaaaaaa')\n console.assert(findMax(['abc', 'cba']) === 'abc')\n console.assert(\n findMax(['play', 'this', 'game', 'of', 'footbott']) === 'footbott'\n )\n console.assert(findMax(['we', 'are', 'gonna', 'rock']) === 'gonna')\n console.assert(findMax(['we', 'are', 'a', 'mad', 'nation']) === 'nation')\n console.assert(findMax(['this', 'is', 'a', 'prrk']) === 'this')\n console.assert(findMax(['b']) === 'b')\n console.assert(findMax(['play', 'play', 'play']) === 'play')\n}\n\ntestFindMax()\n", "declaration": "\nconst findMax = (words) => {\n", "example_test": "const testFindMax = () => {\n console.assert(findMax(['name', 'of', 'string']) === 'string')\n console.assert(findMax(['name', 'enam', 'game']) === 'enam')\n console.assert(findMax(['aaaaaaa', 'bb', 'cc']) === 'aaaaaaa')\n}\ntestFindMax()\n", "buggy_solution": " let s = -1\n let u = -1\n if (words.length == 0) { return '' }\n for (let i = 0; i < words.length; i++) {\n let p = 0\n for (let j = 0; j < words[i].length; j++) {\n let y = 1\n for (let k = 0; k < j; k++) {\n if (words[i][j] == words[i][k]) { y = 0 }\n }\n }\n if (p > s || (p == s && words[i] < words[u])) {\n u = i;\n s = p;\n }\n }\n return words[u]\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "findMax"} -{"task_id": "JavaScript/159", "prompt": "/*\n You're a hungry rabbit, and you already have eaten a certain number of carrots,\n but now you need to eat more carrots to complete the day's meals.\n you should return an array of [ total number of eaten carrots after your meals,\n the number of carrots left after your meals ]\n if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.\n \n Example:\n * eat(5, 6, 10) -> [11, 4]\n * eat(4, 8, 9) -> [12, 1]\n * eat(1, 10, 10) -> [11, 0]\n * eat(2, 11, 5) -> [7, 0]\n \n Variables:\n @number : integer\n the number of carrots that you have eaten.\n @need : integer\n the number of carrots that you need to eat.\n @remaining : integer\n the number of remaining carrots thet exist in stock\n \n Constrain:\n * 0 <= number <= 1000\n * 0 <= need <= 1000\n * 0 <= remaining <= 1000\n\n Have fun :)\n */\nconst eat = (number, need, remaining) => {\n", "canonical_solution": " if (need <= remaining) {\n return [need + number, remaining - need]\n }\n return [remaining + number, 0]\n}\n\n", "test": "const testEat = () => {\n console.assert(JSON.stringify(eat(5, 6, 10)) === JSON.stringify([11, 4]))\n console.assert(JSON.stringify(eat(4, 8, 9)) === JSON.stringify([12, 1]))\n console.assert(JSON.stringify(eat(1, 10, 10)) === JSON.stringify([11, 0]))\n console.assert(JSON.stringify(eat(2, 11, 5)) === JSON.stringify([7, 0]))\n console.assert(JSON.stringify(eat(4, 5, 7)) === JSON.stringify([9, 2]))\n console.assert(JSON.stringify(eat(4, 5, 1)) === JSON.stringify([5, 0]))\n}\n\ntestEat()\n", "declaration": "\nconst eat = (number, need, remaining) => {\n", "example_test": "const testEat = () => {\n console.assert(JSON.stringify(eat(5, 6, 10)) === JSON.stringify([11, 4]))\n console.assert(JSON.stringify(eat(4, 8, 9)) === JSON.stringify([12, 1]))\n console.assert(JSON.stringify(eat(1, 10, 10)) === JSON.stringify([11, 0]))\n console.assert(JSON.stringify(eat(2, 11, 5)) === JSON.stringify([7, 0]))\n}\ntestEat()\n", "buggy_solution": " if (need <= remaining) {\n return [need + number, number + remaining - need]\n }\n return [remaining + need + number, 0]\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "eat"} -{"task_id": "JavaScript/160", "prompt": "/*\n Given two lists operator, and operand. The first list has basic algebra operations, and \n the second list is a list of integers. Use the two given lists to build the algebric \n expression and return the evaluation of this expression.\n\n The basic algebra operations:\n Addition ( + ) \n Subtraction ( - ) \n Multiplication ( * ) \n Floor division ( // ) \n Exponentiation ( ** ) \n\n Example:\n operator['+', '*', '-']\n array = [2, 3, 4, 5]\n result = 2 + 3 * 4 - 5\n => result = 9\n\n Note:\n The length of operator list is equal to the length of operand list minus one.\n Operand is a list of of non-negative integers.\n Operator list has at least one operator, and operand list has at least two operands.\n\n */\nconst doAlgebra = (operator, operand) => {\n", "canonical_solution": " while (operator.length > 0) {\n let y = 0\n for (let i = operator.length - 1; i >= 0; i--) {\n if (operator[i] == '**') {\n let u = operand[i]\n while (operand[i + 1] > 1) {\n operand[i + 1]--;\n operand[i] *= u;\n }\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n for (let i = 0; i < operator.length; i++) {\n if (operator[i] == '*') {\n operand[i] *= operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n else if (operator[i] == '//') {\n operand[i] = (operand[i] - operand[i] % operand[i + 1]) / operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n for (let i = 0; i < operator.length; i++) {\n if (operator[i] == '+') {\n operand[i] += operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n else if (operator[i] == '-') {\n operand[i] -= operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n }\n return operand[0]\n}\n\n", "test": "const testDoAlgebra = () => {\n console.assert(doAlgebra(['**', '*', '+'], [2, 3, 4, 5]) === 37)\n console.assert(doAlgebra(['+', '*', '-'], [2, 3, 4, 5]) === 9)\n console.assert(doAlgebra(['//', '*'], [7, 3, 4]) === 8)\n}\n\ntestDoAlgebra()\n", "declaration": "\nconst doAlgebra = (operator, operand) => {\n", "example_test": "", "buggy_solution": " while (operator.length > 0) {\n let y = 0\n for (let i = operator.length - 1; i >= 0; i--) {\n if (operator[i] == '**') {\n let u = operand[i]\n while (operand[i + 1] > 1) {\n operand[i + 1]--;\n operand[i] *= u;\n }\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n for (let i = 0; i < operator.length; i++) {\n if (operator[i] == '*') {\n operand[i] *= operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n else if (operator[i] == '//') {\n operand[i] = (operand[i + 1] - operand[i] % operand[i + 1]) / operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n for (let i = 0; i < operator.length; i++) {\n if (operator[i] == '+') {\n operand[i] += operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n else if (operator[i] == '-') {\n operand[i] -= operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n }\n return operand[0]\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "doAlgebra"} -{"task_id": "JavaScript/161", "prompt": "/*You are given a string s.\n if s[i] is a letter, reverse its case from lower to upper or vise versa, \n otherwise keep it as it is.\n If the string contains no letters, reverse the string.\n The function should return the resulted string.\n Examples\n solve(\"1234\") = \"4321\"\n solve(\"ab\") = \"AB\"\n solve(\"#a@C\") = \"#A@c\"\n */\nconst solve = (s) => {\n", "canonical_solution": " let t = 0\n let p = ''\n for (let i = 0; i < s.length; i++) {\n let y = s[i].charCodeAt()\n if (y >= 65 && y <= 90) {\n y += 32;\n t = 1;\n } else if (y >= 97 && y <= 122) {\n y -= 32;\n t = 1;\n }\n p += String.fromCharCode(y)\n }\n if (t == 1) { return p }\n let u = ''\n for (let i = 0; i < p.length; i++) {\n u += p[p.length - i - 1]\n }\n return u\n}\n\n", "test": "const testSolve = () => {\n console.assert(solve('AsDf') === 'aSdF')\n console.assert(solve('1234') === '4321')\n console.assert(solve('ab') === 'AB')\n console.assert(solve('#a@C') === '#A@c')\n console.assert(solve('#AsdfW^45') === '#aSDFw^45')\n console.assert(solve('#6@2') === '2@6#')\n console.assert(solve('#$a^D') === '#$A^d')\n console.assert(solve('#ccc') === '#CCC')\n}\n\ntestSolve()\n", "declaration": "\nconst solve = (s) => {\n", "example_test": "const testSolve = () => {\n console.assert(solve('1234') === '4321')\n console.assert(solve('ab') === 'AB')\n console.assert(solve('#a@C') === '#A@c')\n}\ntestSolve()\n", "buggy_solution": " let t = 0\n let p = ''\n for (let i = 0; i < s.length; i++) {\n let y = s[i].charCodeAt()\n if (y >= 65 && y <= 90) {\n y += 32;\n t = 1;\n }\n p += String.fromCharCode(y)\n }\n if (t == 1) { return p }\n let u = ''\n for (let i = 0; i < p.length; i++) {\n u += p[p.length - i - 1]\n }\n return u\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "solve"} -{"task_id": "JavaScript/162", "prompt": "/*\n Given a string 'text', return its md5 hash equivalent string.\n If 'text' is an empty string, return null.\n\n >>> stringToMd5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'\n */\nconst stringToMd5 = (text) => {\n", "canonical_solution": " if (text == '') { return null }\n var md5 = require('js-md5')\n return md5(text)\n}\n\n", "test": "const testStringToMd5 = () => {\n console.assert(\n stringToMd5('Hello world') === '3e25960a79dbc69b674cd4ec67a72c62'\n )\n console.assert(stringToMd5('') === null)\n console.assert(stringToMd5('A B C') === '0ef78513b0cb8cef12743f5aeb35f888')\n console.assert(stringToMd5('password') === '5f4dcc3b5aa765d61d8327deb882cf99')\n}\n\ntestStringToMd5()\n", "declaration": "\nconst stringToMd5 = (text) => {\n", "example_test": "const testStringToMd5 = () => {\n console.assert(\n stringToMd5('Hello world') === '3e25960a79dbc69b674cd4ec67a72c62'\n )\n}\ntestStringToMd5()\n", "buggy_solution": " if (text == '') { return null }\n var md5 = require('js-md5')\n return md5('text')\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "stringToMd5"} -{"task_id": "JavaScript/163", "prompt": "/*\n Given two positive integers a and b, return the even digits between a\n and b, in ascending order.\n\n For example:\n generateIntegers(2, 8) => [2, 4, 6, 8]\n generateIntegers(8, 2) => [2, 4, 6, 8]\n generateIntegers(10, 14) => []\n */\nconst generateIntegers = (a, b) => {\n", "canonical_solution": " if (a > b) {\n let tmp = a;\n a = b;\n b = tmp;\n }\n let y = []\n for (let i = a; i <= b; i++) {\n if (i == 2 || i == 4 || i == 6 || i == 8) { y.push(i) }\n }\n return y\n}\n\n", "test": "const testGenerateIntegers = () => {\n console.assert(\n JSON.stringify(generateIntegers(2, 10)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(10, 2)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(132, 2)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(17, 89)) === JSON.stringify([])\n )\n}\n\ntestGenerateIntegers()\n", "declaration": "\nconst generateIntegers = (a, b) => {\n", "example_test": "const testGenerateIntegers = () => {\n console.assert(\n JSON.stringify(generateIntegers(2, 8)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(8, 2)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(10, 14)) === JSON.stringify([])\n )\n}\ntestGenerateIntegers()\n", "buggy_solution": " if (a > b) {\n let tmp = a;\n a = b;\n b = tmp;\n }\n let y = []\n for (let i = a; i > b; i++) {\n if (i == 2 || i == 4 || i == 6 || i == 8) { y.push(i) }\n }\n return y\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "generateIntegers"} +{"task_id": "JavaScript/0", "prompt": "/* Check if in given list of numbers, are any two numbers closer to each other than\n given threshold.\n >>> hasCloseElements([1.0, 2.0, 3.0], 0.5)\n false\n >>> hasCloseElements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)\n true\n */\nconst hasCloseElements = (numbers, threshold) => {\n", "canonical_solution": " for (let i = 0; i < numbers.length; i++) {\n for (let j = 0; j < numbers.length; j++) {\n if (i != j) {\n let distance = Math.abs(numbers[i] - numbers[j]);\n if (distance < threshold) {\n return true;\n }\n }\n }\n }\n return false;\n}\n\n", "test": "const testHasCloseElements = () => {\n console.assert(hasCloseElements([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.3) === true)\n console.assert(\n hasCloseElements([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.05) === false\n )\n console.assert(hasCloseElements([1.0, 2.0, 5.9, 4.0, 5.0], 0.95) === true)\n console.assert(hasCloseElements([1.0, 2.0, 5.9, 4.0, 5.0], 0.8) === false)\n console.assert(hasCloseElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0], 0.1) === true)\n console.assert(hasCloseElements([1.1, 2.2, 3.1, 4.1, 5.1], 1.0) === true)\n console.assert(hasCloseElements([1.1, 2.2, 3.1, 4.1, 5.1], 0.5) === false)\n}\n\ntestHasCloseElements()\n", "declaration": "\nconst hasCloseElements = (numbers, threshold) => {\n", "example_test": "const testHasCloseElements = () => {\n console.assert(hasCloseElements([1.0, 2.0, 3.0], 0.5) === false)\n console.assert(\n hasCloseElements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3) === true\n )\n}\ntestHasCloseElements()\n", "buggy_solution": " for (let i = 0; i < numbers.length; i++) {\n for (let j = 0; j < numbers.length; j++) {\n if (i != j) {\n let distance = numbers[i] - numbers[j];\n if (distance < threshold) {\n return true;\n }\n }\n }\n }\n return false;\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "hasCloseElements", "signature": "const hasCloseElements = (numbers, threshold)", "docstring": "Check if in given list of numbers, are any two numbers closer to each other than\ngiven threshold.\n>>> hasCloseElements([1.0, 2.0, 3.0], 0.5)\nfalse\n>>> hasCloseElements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)\ntrue", "instruction": "Write a JavaScript function `const hasCloseElements = (numbers, threshold)` to solve the following problem:\nCheck if in given list of numbers, are any two numbers closer to each other than\ngiven threshold.\n>>> hasCloseElements([1.0, 2.0, 3.0], 0.5)\nfalse\n>>> hasCloseElements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)\ntrue"} +{"task_id": "JavaScript/1", "prompt": "/* Input to this function is a string containing multiple groups of nested parentheses. Your goal is to\n separate those group into separate strings and return the list of those.\n Separate groups are balanced (each open brace is properly closed) and not nested within each other\n Ignore any spaces in the input string.\n >>> separateParenGroups('( ) (( )) (( )( ))')\n ['()', '(())', '(()())']\n */\nconst separateParenGroups = (paren_string) => {\n", "canonical_solution": " var result = [];\n var current_string = [];\n var current_depth = 0;\n\n for (const c of paren_string) {\n if (c == '(') {\n current_depth += 1;\n current_string.push(c);\n } else if (c == ')') {\n current_depth -= 1;\n current_string.push(c);\n if (current_depth == 0) {\n result.push(current_string.join(''));\n current_string = [];\n }\n }\n }\n\n return result;\n}\n\n", "test": "const testSeparateParenGroups = () => {\n console.assert(\n JSON.stringify(separateParenGroups('(()()) ((())) () ((())()())')) ===\n JSON.stringify(['(()())', '((()))', '()', '((())()())'])\n )\n console.assert(\n JSON.stringify(separateParenGroups('() (()) ((())) (((())))')) ===\n JSON.stringify(['()', '(())', '((()))', '(((())))'])\n )\n console.assert(\n JSON.stringify(separateParenGroups('(()(())((())))')) ===\n JSON.stringify(['(()(())((())))'])\n )\n console.assert(\n JSON.stringify(separateParenGroups('( ) (( )) (( )( ))')) ===\n JSON.stringify(['()', '(())', '(()())'])\n )\n}\n\ntestSeparateParenGroups()\n", "declaration": "\nconst separateParenGroups = (paren_string) => {\n", "example_test": "const testSeparateParenGroups = () => {\n console.assert(\n JSON.stringify(separateParenGroups('( ) (( )) (( )( ))')) ===\n JSON.stringify(['()', '(())', '(()())'])\n )\n}\ntestSeparateParenGroups()\n", "buggy_solution": " var result = [];\n var current_string = [];\n var current_depth = 0;\n\n for (const c of paren_string) {\n if (c == '(') {\n current_depth += 1;\n current_string.push(c);\n } else if (c == ')') {\n current_depth -= 1;\n current_string.push(c);\n if (current_depth < 0) {\n result.push(current_string.join(''));\n current_string = [];\n }\n }\n }\n\n return result;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "separateParenGroups", "signature": "const separateParenGroups = (paren_string)", "docstring": "Input to this function is a string containing multiple groups of nested parentheses. Your goal is to\nseparate those group into separate strings and return the list of those.\nSeparate groups are balanced (each open brace is properly closed) and not nested within each other\nIgnore any spaces in the input string.\n>>> separateParenGroups('( ) (( )) (( )( ))')\n['()', '(())', '(()())']", "instruction": "Write a JavaScript function `const separateParenGroups = (paren_string)` to solve the following problem:\nInput to this function is a string containing multiple groups of nested parentheses. Your goal is to\nseparate those group into separate strings and return the list of those.\nSeparate groups are balanced (each open brace is properly closed) and not nested within each other\nIgnore any spaces in the input string.\n>>> separateParenGroups('( ) (( )) (( )( ))')\n['()', '(())', '(()())']"} +{"task_id": "JavaScript/2", "prompt": "/* Given a positive floating point number, it can be decomposed into\n and integer part (largest integer smaller than given number) and decimals\n (leftover part always smaller than 1).\n\n Return the decimal part of the number.\n >>> truncateNumber(3.5)\n 0.5\n */\nconst truncateNumber = (number) => {\n", "canonical_solution": " return number % 1.0;\n}\n\n", "test": "const testTruncateNumber = () => {\n console.assert(truncateNumber(3.5) === 0.5)\n\n console.assert(Math.abs(truncateNumber(1.33) - 0.33) < 1e-6)\n\n console.assert(Math.abs(truncateNumber(123.456 - 0.456) < 1e-6))\n}\n\ntestTruncateNumber()\n", "declaration": "\nconst truncateNumber = (number) => {\n", "example_test": "const testTruncateNumber = () => {\n console.assert(truncateNumber(3.5) === 0.5)\n}\ntestTruncateNumber()\n", "buggy_solution": " return number % 1.0 + 1.0;\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "truncateNumber", "signature": "const truncateNumber = (number)", "docstring": "Given a positive floating point number, it can be decomposed into\nand integer part (largest integer smaller than given number) and decimals\n(leftover part always smaller than 1).\nReturn the decimal part of the number.\n>>> truncateNumber(3.5)\n0.5", "instruction": "Write a JavaScript function `const truncateNumber = (number)` to solve the following problem:\nGiven a positive floating point number, it can be decomposed into\nand integer part (largest integer smaller than given number) and decimals\n(leftover part always smaller than 1).\nReturn the decimal part of the number.\n>>> truncateNumber(3.5)\n0.5"} +{"task_id": "JavaScript/3", "prompt": "/* You're given a list of deposit and withdrawal operations on a bank account that starts with\n zero balance. Your task is to detect if at any point the balance of account fallls below zero, and\n at that point function should return true. Otherwise it should return false.\n >>> belowZero([1, 2, 3])\n false\n >>> belowZero([1, 2, -4, 5])\n true\n */\nconst belowZero = (operations) => {\n", "canonical_solution": " var balance = 0;\n for (const op of operations) {\n balance += op;\n if (balance < 0) {\n return true;\n }\n }\n return false;\n}\n\n", "test": "const testBelowZero = () => {\n console.assert(belowZero([]) === false)\n console.assert(belowZero([1, 2, -3, 1, 2, -3]) === false)\n console.assert(belowZero([1, 2, -4, 5, 6]) === true)\n console.assert(belowZero([1, -1, 2, -2, 5, -5, 4, -4]) === false)\n console.assert(belowZero([1, -1, 2, -2, 5, -5, 4, -5]) === true)\n console.assert(belowZero([1, -2, 2, -2, 5, -5, 4, -4]) === true)\n}\n\ntestBelowZero()\n", "declaration": "\nconst belowZero = (operations) => {\n", "example_test": "const testBelowZero = () => {\n console.assert(belowZero([1, 2, 3]) === false)\n console.assert(belowZero([1, 2, -4, 5]) === true)\n}\ntestBelowZero()\n", "buggy_solution": " var balance = 0;\n for (const op of operations) {\n balance += op;\n if (balance == 0) {\n return true;\n }\n }\n return false;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "belowZero", "signature": "const belowZero = (operations)", "docstring": "You're given a list of deposit and withdrawal operations on a bank account that starts with\nzero balance. Your task is to detect if at any point the balance of account fallls below zero, and\nat that point function should return true. Otherwise it should return false.\n>>> belowZero([1, 2, 3])\nfalse\n>>> belowZero([1, 2, -4, 5])\ntrue", "instruction": "Write a JavaScript function `const belowZero = (operations)` to solve the following problem:\nYou're given a list of deposit and withdrawal operations on a bank account that starts with\nzero balance. Your task is to detect if at any point the balance of account fallls below zero, and\nat that point function should return true. Otherwise it should return false.\n>>> belowZero([1, 2, 3])\nfalse\n>>> belowZero([1, 2, -4, 5])\ntrue"} +{"task_id": "JavaScript/4", "prompt": "/* For a given list of input numbers, calculate Mean Absolute Deviation\n around the mean of this dataset.\n Mean Absolute Deviation is the average absolute difference between each\n element and a centerpoint (mean in this case):\n MAD = average | x - x_mean |\n >>> meanAbsoluteDeviation([1.0, 2.0, 3.0, 4.0])\n 1.0\n */\nconst meanAbsoluteDeviation = (numbers) => {\n", "canonical_solution": " var mean = numbers.reduce((prev, item) => {\n return prev + item;\n }, 0) / numbers.length;\n return numbers.reduce((prev, item) => {\n return prev + Math.abs(item - mean);\n }, 0) / numbers.length;\n\n}\n\n", "test": "const testMeanAbsoluteDeviation = () => {\n console.assert(\n Math.abs(meanAbsoluteDeviation([1.0, 2.0, 3.0]) - 2.0 / 3.0) < 1e-6\n )\n console.assert(\n Math.abs(meanAbsoluteDeviation([1.0, 2.0, 3.0, 4.0]) - 1.0) < 1e-6\n )\n console.assert(\n Math.abs(meanAbsoluteDeviation([1.0, 2.0, 3.0, 4.0, 5.0]) - 6.0 / 5.0) < 1e-6\n )\n}\n\ntestMeanAbsoluteDeviation()\n", "declaration": "\nconst meanAbsoluteDeviation = (numbers) => {\n", "example_test": "const testMeanAbsoluteDeviation = () => {\n console.assert(\n Math.abs(meanAbsoluteDeviation([1.0, 2.0, 3.0, 4.0]) - 1.0) < 1e-6\n )\n}\ntestMeanAbsoluteDeviation()\n", "buggy_solution": " var mean = numbers.reduce((prev, item) => {\n return prev + item;\n }, 0) / numbers.length;\n return numbers.reduce((prev, item) => {\n return prev + Math.abs(item - mean);\n }, 0) / mean;\n\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "meanAbsoluteDeviation", "signature": "const meanAbsoluteDeviation = (numbers)", "docstring": "For a given list of input numbers, calculate Mean Absolute Deviation\naround the mean of this dataset.\nMean Absolute Deviation is the average absolute difference between each\nelement and a centerpoint (mean in this case):\nMAD = average | x - x_mean |\n>>> meanAbsoluteDeviation([1.0, 2.0, 3.0, 4.0])\n1.0", "instruction": "Write a JavaScript function `const meanAbsoluteDeviation = (numbers)` to solve the following problem:\nFor a given list of input numbers, calculate Mean Absolute Deviation\naround the mean of this dataset.\nMean Absolute Deviation is the average absolute difference between each\nelement and a centerpoint (mean in this case):\nMAD = average | x - x_mean |\n>>> meanAbsoluteDeviation([1.0, 2.0, 3.0, 4.0])\n1.0"} +{"task_id": "JavaScript/5", "prompt": "/* Insert a number 'delimeter' between every two consecutive elements of input list `numbers'\n >>> intersperse([], 4)\n []\n >>> intersperse([1, 2, 3], 4)\n [1, 4, 2, 4, 3]\n */\nconst intersperse = (numbers, delimeter) => {\n", "canonical_solution": " if (!Array.isArray(numbers) || numbers.length == 0)\n return [];\n var result = [];\n for (const n of numbers) {\n result.push(n, delimeter);\n }\n result.pop();\n return result;\n}\n\n", "test": "const testIntersperse = () => {\n console.assert(JSON.stringify(intersperse([], 7)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(\n intersperse([5, 6, 3, 2], 8)) === JSON.stringify([5, 8, 6, 8, 3, 8, 2])\n )\n console.assert(\n JSON.stringify(\n intersperse([2, 2, 2], 2)) === JSON.stringify([2, 2, 2, 2, 2])\n )\n}\n\ntestIntersperse()\n", "declaration": "\nconst intersperse = (numbers, delimeter) => {\n", "example_test": "const testIntersperse = () => {\n console.assert(JSON.stringify(intersperse([], 4)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(\n intersperse([1,2,3], 4)) === JSON.stringify([1,4,2,4,3])\n )\n}\ntestIntersperse()\n", "buggy_solution": " if (!Array.isArray(numbers) || numbers.length == 0)\n return [];\n var result = [];\n for (const n of numbers) {\n result.push(n, delimeter);\n }\n return result;\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "intersperse", "signature": "const intersperse = (numbers, delimeter)", "docstring": "Insert a number 'delimeter' between every two consecutive elements of input list `numbers'\n>>> intersperse([], 4)\n[]\n>>> intersperse([1, 2, 3], 4)\n[1, 4, 2, 4, 3]", "instruction": "Write a JavaScript function `const intersperse = (numbers, delimeter)` to solve the following problem:\nInsert a number 'delimeter' between every two consecutive elements of input list `numbers'\n>>> intersperse([], 4)\n[]\n>>> intersperse([1, 2, 3], 4)\n[1, 4, 2, 4, 3]"} +{"task_id": "JavaScript/6", "prompt": "/* Input to this function is a string represented multiple groups for nested parentheses separated by spaces.\n For each of the group, output the deepest level of nesting of parentheses.\n E.g. (()()) has maximum two levels of nesting while ((())) has three.\n\n >>> parseNestedParens('(()()) ((())) () ((())()())')\n [2, 3, 1, 3]\n */\nconst parseNestedParens = (paren_string) => {\n", "canonical_solution": " var parseParenGroup = function (s) {\n let depth = 0, max_depth = 0;\n for (const c of s) {\n if (c == '(') {\n depth += 1;\n max_depth = Math.max(max_depth, depth);\n } else {\n depth -= 1;\n }\n }\n return max_depth;\n }\n return paren_string.split(' ')\n .filter(x => x != '')\n .map(x => parseParenGroup(x));\n}\n\n", "test": "const testParseNestedParens = () => {\n console.assert(\n JSON.stringify(parseNestedParens('(()()) ((())) () ((())()())')) ===\n JSON.stringify([2, 3, 1, 3])\n )\n console.assert(\n JSON.stringify(parseNestedParens('() (()) ((())) (((())))')) ===\n JSON.stringify([1, 2, 3, 4])\n )\n console.assert(\n JSON.stringify(parseNestedParens('(()(())((())))')) === JSON.stringify([4])\n )\n}\n\ntestParseNestedParens()\n", "declaration": "\nconst parseNestedParens = (paren_string) => {\n", "example_test": "const testParseNestedParens = () => {\n console.assert(\n JSON.stringify(parseNestedParens('(()()) ((())) () ((())()())')) ===\n JSON.stringify([2, 3, 1, 3])\n )\n}\ntestParseNestedParens()\n", "buggy_solution": " var parseParenGroup = function (s) {\n let depth = 0, max_depth = 0;\n for (const c of s) {\n if (c == '(') {\n depth += 1;\n max_depth = Math.max(max_depth, depth);\n } else {\n max_depth -= 1;\n }\n }\n return max_depth;\n }\n return paren_string.split(' ')\n .filter(x => x != '')\n .map(x => parseParenGroup(x));\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "parseNestedParens", "signature": "const parseNestedParens = (paren_string)", "docstring": "Input to this function is a string represented multiple groups for nested parentheses separated by spaces.\nFor each of the group, output the deepest level of nesting of parentheses.\nE.g. (()()) has maximum two levels of nesting while ((())) has three.\n>>> parseNestedParens('(()()) ((())) () ((())()())')\n[2, 3, 1, 3]", "instruction": "Write a JavaScript function `const parseNestedParens = (paren_string)` to solve the following problem:\nInput to this function is a string represented multiple groups for nested parentheses separated by spaces.\nFor each of the group, output the deepest level of nesting of parentheses.\nE.g. (()()) has maximum two levels of nesting while ((())) has three.\n>>> parseNestedParens('(()()) ((())) () ((())()())')\n[2, 3, 1, 3]"} +{"task_id": "JavaScript/7", "prompt": "/* Filter an input list of strings only for ones that contain given substring\n >>> filterBySubstring([], 'a')\n []\n >>> filterBySubstring(['abc', 'bacd', 'cde', 'array'], 'a')\n ['abc', 'bacd', 'array']\n */\nconst filterBySubstring = (strings, substring) => {\n", "canonical_solution": " return strings.filter(x => x.indexOf(substring) != -1);\n}\n\n", "test": "const testFilterBySubstring = () => {\n console.assert(\n JSON.stringify(filterBySubstring([], 'john')) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(\n filterBySubstring(\n ['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'],\n 'xxx'\n )\n ) === JSON.stringify(['xxx', 'xxxAAA', 'xxx'])\n )\n console.assert(\n JSON.stringify(\n filterBySubstring(\n ['xxx', 'asd', 'aaaxxy', 'john doe', 'xxxAAA', 'xxx'],\n 'xx'\n )\n ) === JSON.stringify(['xxx', 'aaaxxy', 'xxxAAA', 'xxx'])\n )\n console.assert(\n JSON.stringify(\n filterBySubstring(['grunt', 'trumpet', 'prune', 'gruesome'], 'run')\n ) === JSON.stringify(['grunt', 'prune'])\n )\n}\n\ntestFilterBySubstring()\n", "declaration": "\nconst filterBySubstring = (strings, substring) => {\n", "example_test": "const testFilterBySubstring = () => {\n console.assert(\n JSON.stringify(filterBySubstring([], 'a')) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(\n filterBySubstring(\n ['abc', 'bacd', 'cde', 'array'], 'a'\n )\n ) === JSON.stringify(['abc', 'bacd', 'array'])\n )\n}\ntestFilterBySubstring()\n", "buggy_solution": " return strings.filter(x => substring.indexOf(x) != -1);\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "filterBySubstring", "signature": "const filterBySubstring = (strings, substring)", "docstring": "Filter an input list of strings only for ones that contain given substring\n>>> filterBySubstring([], 'a')\n[]\n>>> filterBySubstring(['abc', 'bacd', 'cde', 'array'], 'a')\n['abc', 'bacd', 'array']", "instruction": "Write a JavaScript function `const filterBySubstring = (strings, substring)` to solve the following problem:\nFilter an input list of strings only for ones that contain given substring\n>>> filterBySubstring([], 'a')\n[]\n>>> filterBySubstring(['abc', 'bacd', 'cde', 'array'], 'a')\n['abc', 'bacd', 'array']"} +{"task_id": "JavaScript/8", "prompt": "/* For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.\n Empty sum should be equal to 0 and empty product should be equal to 1.\n >>> sumProduct([])\n (0, 1)\n >>> sumProduct([1, 2, 3, 4])\n (10, 24)\n */\nconst sumProduct = (numbers, int) => {\n", "canonical_solution": " var sum_value = 0, prod_value = 1;\n for (const n of numbers) {\n sum_value += n;\n prod_value *= n;\n }\n return [sum_value, prod_value];\n}\n\n", "test": "const testSumProduct = () => {\n console.assert(JSON.stringify(sumProduct([])) === JSON.stringify([0, 1]))\n console.assert(\n JSON.stringify(sumProduct([1, 1, 1])) === JSON.stringify([3, 1])\n )\n console.assert(\n JSON.stringify(sumProduct([100, 0])) === JSON.stringify([100, 0])\n )\n console.assert(\n JSON.stringify(\n sumProduct([3, 5, 7])) === JSON.stringify([3 + 5 + 7, 3 * 5 * 7])\n )\n console.assert(JSON.stringify(sumProduct([10])) === JSON.stringify([10, 10]))\n}\n\ntestSumProduct()\n", "declaration": "\nconst sumProduct = (numbers, int) => {\n", "example_test": "const testSumProduct = () => {\n console.assert(JSON.stringify(sumProduct([])) === JSON.stringify([0, 1]))\n console.assert(\n JSON.stringify(sumProduct([1, 2,3,4])) === JSON.stringify([10, 24])\n )\n}\ntestSumProduct()\n", "buggy_solution": " var sum_value = 0, prod_value = 0;\n for (const n of numbers) {\n sum_value += n;\n prod_value *= n;\n }\n return [sum_value, prod_value];\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "sumProduct", "signature": "const sumProduct = (numbers, int)", "docstring": "For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.\nEmpty sum should be equal to 0 and empty product should be equal to 1.\n>>> sumProduct([])\n(0, 1)\n>>> sumProduct([1, 2, 3, 4])\n(10, 24)", "instruction": "Write a JavaScript function `const sumProduct = (numbers, int)` to solve the following problem:\nFor a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.\nEmpty sum should be equal to 0 and empty product should be equal to 1.\n>>> sumProduct([])\n(0, 1)\n>>> sumProduct([1, 2, 3, 4])\n(10, 24)"} +{"task_id": "JavaScript/9", "prompt": "/* From a given list of integers, generate a list of rolling maximum element found until given moment\n in the sequence.\n >>> rollingMax([1, 2, 3, 2, 3, 4, 2])\n [1, 2, 3, 3, 3, 4, 4]\n */\nconst rollingMax = (numbers) => {\n", "canonical_solution": " var running_max, result = [];\n for (const n of numbers) {\n if (running_max == undefined)\n running_max = n;\n else\n running_max = Math.max(running_max, n);\n result.push(running_max);\n }\n return result;\n}\n\n", "test": "const testRollingMax = () => {\n console.assert(JSON.stringify(rollingMax([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(rollingMax([1, 2, 3, 4])) === JSON.stringify([1, 2, 3, 4])\n )\n console.assert(\n JSON.stringify(rollingMax([4, 3, 2, 1])) === JSON.stringify([4, 4, 4, 4])\n )\n console.assert(\n JSON.stringify(\n rollingMax([3, 2, 3, 100, 3])) === JSON.stringify([3, 3, 3, 100, 100])\n )\n}\n\ntestRollingMax()\n", "declaration": "\nconst rollingMax = (numbers) => {\n", "example_test": "const testRollingMax = () => {\n console.assert(JSON.stringify(rollingMax([1, 2, 3, 2, 3, 4, 2])) === JSON.stringify([1, 2, 3, 3, 3, 4, 4]))\n}\ntestRollingMax()\n", "buggy_solution": " var running_max, result = [];\n for (const n of numbers) {\n if (running_max == undefined)\n running_max = n;\n else\n running_max = Math.max(numbers);\n result.push(running_max);\n }\n return result;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "rollingMax", "signature": "const rollingMax = (numbers)", "docstring": "From a given list of integers, generate a list of rolling maximum element found until given moment\nin the sequence.\n>>> rollingMax([1, 2, 3, 2, 3, 4, 2])\n[1, 2, 3, 3, 3, 4, 4]", "instruction": "Write a JavaScript function `const rollingMax = (numbers)` to solve the following problem:\nFrom a given list of integers, generate a list of rolling maximum element found until given moment\nin the sequence.\n>>> rollingMax([1, 2, 3, 2, 3, 4, 2])\n[1, 2, 3, 3, 3, 4, 4]"} +{"task_id": "JavaScript/10", "prompt": "/* Test if gniven strig is a palindrome */\nconst isPalindrome = (string) => {\n return string == string.split('').reverse().join('');\n}\n\n/* Find the shortest palindrome that begins with a supplied string.\n Algorithm idea is simple:\n - Find the longest postfix of supplied string that is a palindrome.\n - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.\n >>> makePalindrome('')\n ''\n >>> makePalindrome('cat')\n 'catac'\n >>> makePalindrome('cata')\n 'catac'\n */\nconst makePalindrome = (string) => {\n", "canonical_solution": " if (string == '')\n return '';\n var beginning_of_suffix = 0;\n while (!isPalindrome(string.slice(beginning_of_suffix)))\n beginning_of_suffix += 1;\n return string + string.slice(0, beginning_of_suffix).split('').reverse().join('');\n}\n\n", "test": "const testmakePalindrome = () => {\n console.assert(makePalindrome('') === '')\n console.assert(makePalindrome('x') === 'x')\n console.assert(makePalindrome('xyz') === 'xyzyx')\n console.assert(makePalindrome('xyx') === 'xyx')\n console.assert(makePalindrome('jerry') === 'jerryrrej')\n}\n\ntestmakePalindrome()\n", "declaration": "const isPalindrome = (string) => {\n return string == string.split('').reverse().join('');\n}\n\nconst makePalindrome = (string) => {\n", "example_test": "const testmakePalindrome = () => {\n console.assert(makePalindrome('') === '')\n console.assert(makePalindrome('cat') === 'catac')\n console.assert(makePalindrome('cata') === 'catac')\n}\ntestmakePalindrome()\n", "buggy_solution": " if (string == '')\n return '';\n var beginning_of_suffix = 0;\n while (!isPalindrome(string))\n beginning_of_suffix += 1;\n return string + string.slice(0, beginning_of_suffix).split('').reverse().join('');\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "stackoverflow", "entry_point": "makePalindrome", "signature": "const makePalindrome = (string)", "docstring": "Find the shortest palindrome that begins with a supplied string.\nAlgorithm idea is simple:\n- Find the longest postfix of supplied string that is a palindrome.\n- Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.\n>>> makePalindrome('')\n''\n>>> makePalindrome('cat')\n'catac'\n>>> makePalindrome('cata')\n'catac'", "instruction": "Write a JavaScript function `const makePalindrome = (string)` to solve the following problem:\nFind the shortest palindrome that begins with a supplied string.\nAlgorithm idea is simple:\n- Find the longest postfix of supplied string that is a palindrome.\n- Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.\n>>> makePalindrome('')\n''\n>>> makePalindrome('cat')\n'catac'\n>>> makePalindrome('cata')\n'catac'"} +{"task_id": "JavaScript/11", "prompt": "/* Input are two strings a and b consisting only of 1s and 0s.\n Perform binary XOR on these inputs and return result also as a string.\n >>> stringXor('010', '110')\n '100'\n */\nconst stringXor = (a, b) => {\n", "canonical_solution": " var xor = function (i, j) {\n if (i == j)\n return '0';\n else\n return '1';\n }\n return a.split('').map((item, index) => xor(item, b[index])).join('');\n}\n\n", "test": "const testStringXor = () => {\n console.assert(stringXor('111000', '101010') === '010010')\n console.assert(stringXor('1', '1') === '0')\n console.assert(stringXor('0101', '0000') === '0101')\n}\n\ntestStringXor()\n", "declaration": "\nconst stringXor = (a, b) => {\n", "example_test": "const testStringXor = () => {\n console.assert(stringXor('010', '110') === '100')\n}\ntestStringXor()\n", "buggy_solution": " var xor = function (i, j) {\n if (i == j)\n return '1';\n else\n return '0';\n }\n return a.split('').map((item, index) => xor(item, b[index])).join('');\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "stringXor", "signature": "const stringXor = (a, b)", "docstring": "Input are two strings a and b consisting only of 1s and 0s.\nPerform binary XOR on these inputs and return result also as a string.\n>>> stringXor('010', '110')\n'100'", "instruction": "Write a JavaScript function `const stringXor = (a, b)` to solve the following problem:\nInput are two strings a and b consisting only of 1s and 0s.\nPerform binary XOR on these inputs and return result also as a string.\n>>> stringXor('010', '110')\n'100'"} +{"task_id": "JavaScript/12", "prompt": "/* Out of list of strings, return the longest one. Return the first one in case of multiple\n strings of the same length. Return null in case the input list is empty.\n >>> longest([])\n\n >>> longest(['a', 'b', 'c'])\n 'a'\n >>> longest(['a', 'bb', 'ccc'])\n 'ccc'\n */\nconst longest = (strings) => {\n", "canonical_solution": " if (!Array.isArray(strings) || strings.length == 0)\n return null;\n var maxlen = Math.max(...strings.map(x => x.length));\n for (const s of strings) {\n if (s.length == maxlen) {\n return s;\n }\n }\n}\n\n", "test": "const testLongest = () => {\n console.assert(longest([]) === null)\n console.assert(longest(['x', 'y', 'z']) === 'x')\n console.assert(longest(['x', 'yyy', 'zzzz', 'www', 'kkkk', 'abc']) === 'zzzz')\n}\n\ntestLongest()\n", "declaration": "\nconst longest = (strings) => {\n", "example_test": "const testLongest = () => {\n console.assert(longest([]) === null)\n console.assert(longest(['a', 'b', 'c']) === 'a')\n console.assert(longest(['a', 'bb', 'ccc']) === 'ccc')\n}\ntestLongest()\n", "buggy_solution": " if (!Array.isArray(strings) || strings.length == 0)\n return null;\n var maxlen = Math.max(...strings.map(x => x.length));\n for (const s of strings) {\n if (s.length > maxlen) {\n return s;\n }\n }\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "longest", "signature": "const longest = (strings)", "docstring": "Out of list of strings, return the longest one. Return the first one in case of multiple\nstrings of the same length. Return null in case the input list is empty.\n>>> longest([])\n>>> longest(['a', 'b', 'c'])\n'a'\n>>> longest(['a', 'bb', 'ccc'])\n'ccc'", "instruction": "Write a JavaScript function `const longest = (strings)` to solve the following problem:\nOut of list of strings, return the longest one. Return the first one in case of multiple\nstrings of the same length. Return null in case the input list is empty.\n>>> longest([])\n>>> longest(['a', 'b', 'c'])\n'a'\n>>> longest(['a', 'bb', 'ccc'])\n'ccc'"} +{"task_id": "JavaScript/13", "prompt": "/* Return a greatest common divisor of two integers a and b\n >>> greatestCommonDivisor(3, 5)\n 1\n >>> greatestCommonDivisor(25, 15)\n 5\n */\nconst greatestCommonDivisor = (a, b) => {\n", "canonical_solution": " while (b != 0) {\n let temp = a;\n a = b;\n b = temp % b;\n }\n return a;\n}\n\n", "test": "const testGreatestCommonDivisor = () => {\n console.assert(greatestCommonDivisor(3, 7) === 1)\n console.assert(greatestCommonDivisor(10, 15) === 5)\n console.assert(greatestCommonDivisor(49, 14) === 7)\n console.assert(greatestCommonDivisor(144, 60) === 12)\n}\n\ntestGreatestCommonDivisor()\n", "declaration": "\nconst greatestCommonDivisor = (a, b) => {\n", "example_test": "const testGreatestCommonDivisor = () => {\n console.assert(greatestCommonDivisor(3, 5) === 1)\n console.assert(greatestCommonDivisor(25, 15) === 5)\n}\ntestGreatestCommonDivisor()\n", "buggy_solution": " while (b != 0) {\n let temp = a;\n a = b;\n b = temp % b;\n }\n return b;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "greatestCommonDivisor", "signature": "const greatestCommonDivisor = (a, b)", "docstring": "Return a greatest common divisor of two integers a and b\n>>> greatestCommonDivisor(3, 5)\n1\n>>> greatestCommonDivisor(25, 15)\n5", "instruction": "Write a JavaScript function `const greatestCommonDivisor = (a, b)` to solve the following problem:\nReturn a greatest common divisor of two integers a and b\n>>> greatestCommonDivisor(3, 5)\n1\n>>> greatestCommonDivisor(25, 15)\n5"} +{"task_id": "JavaScript/14", "prompt": "/* Return list of all prefixes from shortest to longest of the input string\n >>> allPrefixes('abc')\n ['a', 'ab', 'abc']\n */\nconst allPrefixes = (string) => {\n", "canonical_solution": " var result = [];\n for (let i = 0; i < string.length; i++) {\n result.push(string.slice(0, i+1));\n }\n return result;\n}\n\n", "test": "const testAllPrefixes = () => {\n console.assert(JSON.stringify(allPrefixes('')) === JSON.stringify([]))\n console.assert(\n JSON.stringify(\n allPrefixes('asdfgh')) ===\n JSON.stringify(['a', 'as', 'asd', 'asdf', 'asdfg', 'asdfgh'])\n )\n console.assert(\n JSON.stringify(allPrefixes('WWW')) === JSON.stringify(['W', 'WW', 'WWW'])\n )\n}\n\ntestAllPrefixes()\n", "declaration": "\nconst allPrefixes = (string) => {\n", "example_test": "const testAllPrefixes = () => {\n console.assert(\n JSON.stringify(\n allPrefixes('abc')) ===\n JSON.stringify(['a', 'ab', 'abc'])\n )\n}\ntestAllPrefixes()\n", "buggy_solution": " var result = [];\n for (let i = 0; i < string.length-1; i++) {\n result.push(string.slice(0, i+1));\n }\n return result;\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "allPrefixes", "signature": "const allPrefixes = (string)", "docstring": "Return list of all prefixes from shortest to longest of the input string\n>>> allPrefixes('abc')\n['a', 'ab', 'abc']", "instruction": "Write a JavaScript function `const allPrefixes = (string)` to solve the following problem:\nReturn list of all prefixes from shortest to longest of the input string\n>>> allPrefixes('abc')\n['a', 'ab', 'abc']"} +{"task_id": "JavaScript/15", "prompt": "/* Return a string containing space-delimited numbers starting from 0 upto n inclusive.\n >>> stringSequence(0)\n '0'\n >>> stringSequence(5)\n '0 1 2 3 4 5'\n */\nconst stringSequence = (n) => {\n", "canonical_solution": " return [...Array(n).keys(), n].join(' ')\n}\n\n", "test": "const testStringSequence = () => {\n console.assert(stringSequence(0) === '0')\n console.assert(stringSequence(3) === '0 1 2 3')\n console.assert(stringSequence(10) === '0 1 2 3 4 5 6 7 8 9 10')\n}\n\ntestStringSequence()\n", "declaration": "\nconst stringSequence = (n) => {\n", "example_test": "const testStringSequence = () => {\n console.assert(stringSequence(0) === '0')\n console.assert(stringSequence(5) === '0 1 2 3 4 5')\n}\ntestStringSequence()\n", "buggy_solution": " return [...Array(n-1).keys(), n].join(' ')\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "stringSequence", "signature": "const stringSequence = (n)", "docstring": "Return a string containing space-delimited numbers starting from 0 upto n inclusive.\n>>> stringSequence(0)\n'0'\n>>> stringSequence(5)\n'0 1 2 3 4 5'", "instruction": "Write a JavaScript function `const stringSequence = (n)` to solve the following problem:\nReturn a string containing space-delimited numbers starting from 0 upto n inclusive.\n>>> stringSequence(0)\n'0'\n>>> stringSequence(5)\n'0 1 2 3 4 5'"} +{"task_id": "JavaScript/16", "prompt": "/* Given a string, find out how many distinct characters (regardless of case) does it consist of\n >>> countDistinctCharacters('xyzXYZ')\n 3\n >>> countDistinctCharacters('Jerry')\n 4\n */\nconst countDistinctCharacters = (string) => {\n", "canonical_solution": " return (new Set(string.toLowerCase())).size;\n\n}\n\n", "test": "const testCountDistinctCharacters = () => {\n console.assert(countDistinctCharacters('') === 0)\n console.assert(countDistinctCharacters('abcde') === 5)\n console.assert(countDistinctCharacters('abcde' + 'cade' + 'CADE') === 5)\n console.assert(countDistinctCharacters('aaaaAAAAaaaa') === 1)\n console.assert(countDistinctCharacters('Jerry jERRY JeRRRY') === 5)\n}\n\ntestCountDistinctCharacters()\n", "declaration": "\nconst countDistinctCharacters = (string) => {\n", "example_test": "const testCountDistinctCharacters = () => {\n console.assert(countDistinctCharacters('xyzXYZ') === 3)\n console.assert(countDistinctCharacters('Jerry') === 4)\n}\ntestCountDistinctCharacters()\n", "buggy_solution": " return (new Set(string)).size;\n\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "countDistinctCharacters", "signature": "const countDistinctCharacters = (string)", "docstring": "Given a string, find out how many distinct characters (regardless of case) does it consist of\n>>> countDistinctCharacters('xyzXYZ')\n3\n>>> countDistinctCharacters('Jerry')\n4", "instruction": "Write a JavaScript function `const countDistinctCharacters = (string)` to solve the following problem:\nGiven a string, find out how many distinct characters (regardless of case) does it consist of\n>>> countDistinctCharacters('xyzXYZ')\n3\n>>> countDistinctCharacters('Jerry')\n4"} +{"task_id": "JavaScript/17", "prompt": "/* Input to this function is a string representing musical notes in a special ASCII format.\n Your task is to parse this string and return list of integers corresponding to how many beats does each\n not last.\n\n Here is a legend:\n 'o' - whole note, lasts four beats\n 'o|' - half note, lasts two beats\n '.|' - quater note, lasts one beat\n\n >>> parseMusic('o o| .| o| o| .| .| .| .| o o')\n [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]\n */\nconst parseMusic = (music_string) => {\n", "canonical_solution": " const note_map = {'o': 4, 'o|': 2, '.|': 1};\n return music_string.split(' ').filter(x => x != '').map(x => note_map[x]);\n}\n\n", "test": "const testParseMusic = () => {\n console.assert(JSON.stringify(parseMusic('')) === JSON.stringify([]))\n console.assert(\n JSON.stringify(parseMusic('o o o o')) === JSON.stringify([4, 4, 4, 4])\n )\n console.assert(\n JSON.stringify(parseMusic('.| .| .| .|')) === JSON.stringify([1, 1, 1, 1])\n )\n console.assert(\n JSON.stringify(parseMusic('o| o| .| .| o o o o')) ===\n JSON.stringify([2, 2, 1, 1, 4, 4, 4, 4])\n )\n console.assert(\n JSON.stringify(parseMusic('o| .| o| .| o o| o o|')) ===\n JSON.stringify([2, 1, 2, 1, 4, 2, 4, 2])\n )\n}\n\ntestParseMusic()\n", "declaration": "\nconst parseMusic = (music_string) => {\n", "example_test": "const testParseMusic = () => {\n console.assert(JSON.stringify(parseMusic('o o| .| o| o| .| .| .| .| o o')) === JSON.stringify([4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]))\n}\ntestParseMusic()\n", "buggy_solution": " const note_map = {'o': 3, 'o|': 2, '.|': 1};\n return music_string.split(' ').filter(x => x != '').map(x => note_map[x]);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "parseMusic", "signature": "const parseMusic = (music_string)", "docstring": "Input to this function is a string representing musical notes in a special ASCII format.\nYour task is to parse this string and return list of integers corresponding to how many beats does each\nnot last.\nHere is a legend:\n'o' - whole note, lasts four beats\n'o|' - half note, lasts two beats\n'.|' - quater note, lasts one beat\n>>> parseMusic('o o| .| o| o| .| .| .| .| o o')\n[4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]", "instruction": "Write a JavaScript function `const parseMusic = (music_string)` to solve the following problem:\nInput to this function is a string representing musical notes in a special ASCII format.\nYour task is to parse this string and return list of integers corresponding to how many beats does each\nnot last.\nHere is a legend:\n'o' - whole note, lasts four beats\n'o|' - half note, lasts two beats\n'.|' - quater note, lasts one beat\n>>> parseMusic('o o| .| o| o| .| .| .| .| o o')\n[4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]"} +{"task_id": "JavaScript/18", "prompt": "/* Find how many times a given substring can be found in the original string. Count overlaping cases.\n >>> howManyTimes('', 'a')\n 0\n >>> howManyTimes('aaa', 'a')\n 3\n >>> howManyTimes('aaaa', 'aa')\n 3\n */\nconst howManyTimes = (string, substring) => {\n", "canonical_solution": " var times = 0;\n for (let i = 0; i < string.length - substring.length + 1; i++) {\n if (string.slice(i, i+substring.length) == substring) {\n times += 1;\n }\n }\n return times;\n}\n\n", "test": "const testHowManyTimes = () => {\n console.assert(howManyTimes('', 'x') === 0)\n console.assert(howManyTimes('xyxyxyx', 'x') === 4)\n console.assert(howManyTimes('cacacacac', 'cac') === 4)\n console.assert(howManyTimes('john doe', 'john') === 1)\n}\n\ntestHowManyTimes()\n", "declaration": "\nconst howManyTimes = (string, substring) => {\n", "example_test": "const testHowManyTimes = () => {\n console.assert(howManyTimes('', 'a') === 0)\n console.assert(howManyTimes('aaa', 'a') === 3)\n console.assert(howManyTimes('aaaa', 'aa') === 3)\n}\ntestHowManyTimes()\n", "buggy_solution": " var times = 0;\n for (let i = 0; i < string.length - substring.length; i++) {\n if (string.slice(i, i+substring.length) == substring) {\n times += 1;\n }\n }\n return times;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "howManyTimes", "signature": "const howManyTimes = (string, substring)", "docstring": "Find how many times a given substring can be found in the original string. Count overlaping cases.\n>>> howManyTimes('', 'a')\n0\n>>> howManyTimes('aaa', 'a')\n3\n>>> howManyTimes('aaaa', 'aa')\n3", "instruction": "Write a JavaScript function `const howManyTimes = (string, substring)` to solve the following problem:\nFind how many times a given substring can be found in the original string. Count overlaping cases.\n>>> howManyTimes('', 'a')\n0\n>>> howManyTimes('aaa', 'a')\n3\n>>> howManyTimes('aaaa', 'aa')\n3"} +{"task_id": "JavaScript/19", "prompt": "/* Input is a space-delimited string of numberals from 'zero' to 'nine'.\n Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.\n Return the string with numbers sorted from smallest to largest\n >>> sortNumbers('three one five')\n 'one three five'\n */\nconst sortNumbers = (numbers) => {\n", "canonical_solution": " const value_map = {\n 'zero': 0,\n 'one': 1,\n 'two': 2,\n 'three': 3,\n 'four': 4,\n 'five': 5,\n 'six': 6,\n 'seven': 7,\n 'eight': 8,\n 'nine': 9\n };\n return numbers.split(' ')\n .filter(x => x != '')\n .sort((a, b) => value_map[a] - value_map[b])\n .join(' ');\n}\n\n", "test": "const testSortNumbers = () => {\n console.assert(sortNumbers('') === '')\n console.assert(sortNumbers('three') === 'three')\n console.assert(sortNumbers('three five nine') === 'three five nine')\n console.assert(\n sortNumbers(\n 'five zero four seven nine eight') === 'zero four five seven eight nine'\n )\n console.assert(\n sortNumbers(\n 'six five four three two one zero') === 'zero one two three four five six'\n )\n}\n\ntestSortNumbers()\n", "declaration": "\nconst sortNumbers = (numbers) => {\n", "example_test": "const testSortNumbers = () => {\n console.assert(sortNumbers('three one five') === 'one three five')\n}\ntestSortNumbers()\n", "buggy_solution": " const value_map = {\n 'zero': 0,\n 'one': 1,\n 'two': 2,\n 'three': 3,\n 'four': 4,\n 'five': 5,\n 'six': 6,\n 'seven': 7,\n 'eight': 8,\n 'nine': 9\n };\n return numbers.split(' ')\n .filter(x => x != '')\n .join(' ');\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sortNumbers", "signature": "const sortNumbers = (numbers)", "docstring": "Input is a space-delimited string of numberals from 'zero' to 'nine'.\nValid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.\nReturn the string with numbers sorted from smallest to largest\n>>> sortNumbers('three one five')\n'one three five'", "instruction": "Write a JavaScript function `const sortNumbers = (numbers)` to solve the following problem:\nInput is a space-delimited string of numberals from 'zero' to 'nine'.\nValid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.\nReturn the string with numbers sorted from smallest to largest\n>>> sortNumbers('three one five')\n'one three five'"} +{"task_id": "JavaScript/20", "prompt": "/* From a supplied list of numbers (of length at least two) select and return two that are the closest to each\n other and return them in order (smaller number, larger number).\n >>> findClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2])\n (2.0, 2.2)\n >>> findClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0])\n (2.0, 2.0)\n */\nconst findClosestElements = (numbers) => {\n", "canonical_solution": " var closest_pair, distance;\n for (let i = 0; i < numbers.length; i++)\n for (let j = 0; j < numbers.length; j++)\n if (i != j) {\n let a = numbers[i], b = numbers[j];\n if (distance == null) {\n distance = Math.abs(a - b);\n closest_pair = [Math.min(a, b), Math.max(a, b)];\n } else {\n let new_distance = Math.abs(a - b);\n if (new_distance < distance) {\n distance = new_distance;\n closest_pair = [Math.min(a, b), Math.max(a, b)];\n }\n }\n }\n return closest_pair;\n}\n\n", "test": "const testFindClosestElements = () => {\n console.assert(\n JSON.stringify(findClosestElements([1.0, 2.0, 3.9, 4.0, 5.0, 2.2])) ===\n JSON.stringify([3.9, 4.0])\n )\n console.assert(\n JSON.stringify(findClosestElements([1.0, 2.0, 5.9, 4.0, 5.0])) ===\n JSON.stringify([5.0, 5.9])\n )\n console.assert(\n JSON.stringify(findClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2])) ===\n JSON.stringify([2.0, 2.2])\n )\n console.assert(\n JSON.stringify(findClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0])) ===\n JSON.stringify([2.0, 2.0])\n )\n console.assert(\n JSON.stringify(findClosestElements([1.1, 2.2, 3.1, 4.1, 5.1])) ===\n JSON.stringify([2.2, 3.1])\n )\n}\n\ntestFindClosestElements()\n", "declaration": "\nconst findClosestElements = (numbers) => {\n", "example_test": "const testFindClosestElements = () => {\n console.assert(\n JSON.stringify(findClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2])) ===\n JSON.stringify([2.0, 2.2])\n )\n console.assert(\n JSON.stringify(findClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0])) ===\n JSON.stringify([2.0, 2.0])\n )\n}\ntestFindClosestElements()\n", "buggy_solution": " var closest_pair, distance;\n for (let i = 0; i < numbers.length; i++)\n for (let j = 0; j < numbers.length; j++)\n if (i != j) {\n let a = numbers[i], b = numbers[j];\n if (distance == null) {\n distance = Math.abs(a - b);\n closest_pair = [Math.min(a, b), Math.max(a, b)];\n } else {\n let new_distance = Math.abs(a - b);\n if (new_distance > distance) {\n distance = new_distance;\n closest_pair = [Math.min(a, b), Math.max(a, b)];\n }\n }\n }\n return closest_pair;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "findClosestElements", "signature": "const findClosestElements = (numbers)", "docstring": "From a supplied list of numbers (of length at least two) select and return two that are the closest to each\nother and return them in order (smaller number, larger number).\n>>> findClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2])\n(2.0, 2.2)\n>>> findClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0])\n(2.0, 2.0)", "instruction": "Write a JavaScript function `const findClosestElements = (numbers)` to solve the following problem:\nFrom a supplied list of numbers (of length at least two) select and return two that are the closest to each\nother and return them in order (smaller number, larger number).\n>>> findClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2])\n(2.0, 2.2)\n>>> findClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0])\n(2.0, 2.0)"} +{"task_id": "JavaScript/21", "prompt": "/* Given list of numbers (of at least two elements), apply a linear transform to that list,\n such that the smallest number will become 0 and the largest will become 1\n >>> rescaleToUnit([1.0, 2.0, 3.0, 4.0, 5.0])\n [0.0, 0.25, 0.5, 0.75, 1.0]\n */\nconst rescaleToUnit = (numbers) => {\n", "canonical_solution": " var min_number = Math.min(...numbers);\n var max_number = Math.max(...numbers);\n return numbers.map(x => (x - min_number) / (max_number - min_number));\n}\n\n", "test": "const testRescaleToUnit = () => {\n console.assert(\n JSON.stringify(rescaleToUnit([2.0, 49.9])) === JSON.stringify([0.0, 1.0])\n )\n console.assert(\n JSON.stringify(rescaleToUnit([100.0, 49.9])) === JSON.stringify([1.0, 0.0])\n )\n console.assert(\n JSON.stringify(rescaleToUnit([1.0, 2.0, 3.0, 4.0, 5.0])) ===\n JSON.stringify([0.0, 0.25, 0.5, 0.75, 1.0])\n )\n console.assert(\n JSON.stringify(rescaleToUnit([2.0, 1.0, 5.0, 3.0, 4.0])) ===\n JSON.stringify([0.25, 0.0, 1.0, 0.5, 0.75])\n )\n console.assert(\n JSON.stringify(rescaleToUnit([12.0, 11.0, 15.0, 13.0, 14.0])) ===\n JSON.stringify([0.25, 0.0, 1.0, 0.5, 0.75])\n )\n}\n\ntestRescaleToUnit()\n", "declaration": "\nconst rescaleToUnit = (numbers) => {\n", "example_test": "const testRescaleToUnit = () => {\n console.assert(\n JSON.stringify(rescaleToUnit([1.0, 2.0, 3.0, 4.0, 5.0])) ===\n JSON.stringify([0.0, 0.25, 0.5, 0.75, 1.0])\n )\n}\ntestRescaleToUnit()\n", "buggy_solution": " var min_number = Math.min(...numbers);\n var max_number = Math.max(...numbers);\n return numbers.map(x => (x - min_number) / (max_number + min_number));\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "rescaleToUnit", "signature": "const rescaleToUnit = (numbers)", "docstring": "Given list of numbers (of at least two elements), apply a linear transform to that list,\nsuch that the smallest number will become 0 and the largest will become 1\n>>> rescaleToUnit([1.0, 2.0, 3.0, 4.0, 5.0])\n[0.0, 0.25, 0.5, 0.75, 1.0]", "instruction": "Write a JavaScript function `const rescaleToUnit = (numbers)` to solve the following problem:\nGiven list of numbers (of at least two elements), apply a linear transform to that list,\nsuch that the smallest number will become 0 and the largest will become 1\n>>> rescaleToUnit([1.0, 2.0, 3.0, 4.0, 5.0])\n[0.0, 0.25, 0.5, 0.75, 1.0]"} +{"task_id": "JavaScript/22", "prompt": "/* Filter given list of any python values only for integers\n >>> filterIntegers(['a', 3.14, 5])\n [5]\n >>> filterIntegers([1, 2, 3, 'abc', {}, []])\n [1, 2, 3]\n */\nconst filterIntegers = (values) => {\n", "canonical_solution": " return values.filter(x => Number.isInteger(x));\n}\n\n", "test": "const testFilterIntegers = () => {\n console.assert(JSON.stringify(filterIntegers([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(filterIntegers([4, {}, [], 23.2, 9, 'adasd'])) ===\n JSON.stringify([4, 9])\n )\n console.assert(\n JSON.stringify(filterIntegers([3, 'c', 3, 3, 'a', 'b'])) ===\n JSON.stringify([3, 3, 3])\n )\n}\n\ntestFilterIntegers()\n", "declaration": "\nconst filterIntegers = (values) => {\n", "example_test": "const testFilterIntegers = () => {\n console.assert(JSON.stringify(filterIntegers(['a', 3.14, 5])) === JSON.stringify([5]))\n console.assert(\n JSON.stringify(filterIntegers([1, 2, 3, 'abc', {}, []])) ===\n JSON.stringify([1,2,3])\n )\n}\ntestFilterIntegers()\n", "buggy_solution": " values.filter(x => Number.isInteger(x));\n return values;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "filterIntegers", "signature": "const filterIntegers = (values)", "docstring": "Filter given list of any python values only for integers\n>>> filterIntegers(['a', 3.14, 5])\n[5]\n>>> filterIntegers([1, 2, 3, 'abc', {}, []])\n[1, 2, 3]", "instruction": "Write a JavaScript function `const filterIntegers = (values)` to solve the following problem:\nFilter given list of any python values only for integers\n>>> filterIntegers(['a', 3.14, 5])\n[5]\n>>> filterIntegers([1, 2, 3, 'abc', {}, []])\n[1, 2, 3]"} +{"task_id": "JavaScript/23", "prompt": "/* Return length of given string\n >>> strlen('')\n 0\n >>> strlen('abc')\n 3\n */\nconst strlen = (string) => {\n", "canonical_solution": " return string.length;\n}\n\n", "test": "const testStrlen = () => {\n console.assert(strlen('') === 0)\n console.assert(strlen('x') === 1)\n console.assert(strlen('asdasnakj') === 9)\n}\n\ntestStrlen()\n", "declaration": "\nconst strlen = (string) => {\n", "example_test": "const testStrlen = () => {\n console.assert(strlen('') === 0)\n console.assert(strlen('abc') === 3)\n}\ntestStrlen()\n", "buggy_solution": " return string.length - 1;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "strlen", "signature": "const strlen = (string)", "docstring": "Return length of given string\n>>> strlen('')\n0\n>>> strlen('abc')\n3", "instruction": "Write a JavaScript function `const strlen = (string)` to solve the following problem:\nReturn length of given string\n>>> strlen('')\n0\n>>> strlen('abc')\n3"} +{"task_id": "JavaScript/24", "prompt": "/* For a given number n, find the largest number that divides n evenly, smaller than n\n >>> largestDivisor(15)\n 5\n */\nconst largestDivisor = (n) => {\n", "canonical_solution": " for (let i = n - 1; i >= 0; i--)\n if (n % i == 0)\n return i;\n}\n\n", "test": "const testLargestDivisor = () => {\n console.assert(largestDivisor(3) === 1)\n console.assert(largestDivisor(7) === 1)\n console.assert(largestDivisor(10) === 5)\n console.assert(largestDivisor(100) === 50)\n console.assert(largestDivisor(49) === 7)\n}\n\ntestLargestDivisor()\n", "declaration": "\nconst largestDivisor = (n) => {\n", "example_test": "const testLargestDivisor = () => {\n console.assert(largestDivisor(15) === 5)\n}\ntestLargestDivisor()\n", "buggy_solution": " for (let i = n - 1; i >= 0; i--)\n if (n - i == 0)\n return i;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "largestDivisor", "signature": "const largestDivisor = (n)", "docstring": "For a given number n, find the largest number that divides n evenly, smaller than n\n>>> largestDivisor(15)\n5", "instruction": "Write a JavaScript function `const largestDivisor = (n)` to solve the following problem:\nFor a given number n, find the largest number that divides n evenly, smaller than n\n>>> largestDivisor(15)\n5"} +{"task_id": "JavaScript/25", "prompt": "/* Return list of prime factors of given integer in the order from smallest to largest.\n Each of the factors should be listed number of times corresponding to how many times it appeares in factorization.\n Input number should be equal to the product of all factors\n >>> factorize(8)\n [2, 2, 2]\n >>> factorize(25)\n [5, 5]\n >>> factorize(70)\n [2, 5, 7]\n */\nconst factorize = (n) => {\n", "canonical_solution": " var fact = [], i = 2;\n while (i <= Math.sqrt(n) + 1) {\n if (n % i == 0) {\n fact.push(i);\n n = n / i;\n } else {\n i += 1;\n }\n }\n\n if (n > 1)\n fact.push(n);\n return fact;\n}\n\n", "test": "const testFactorize = () => {\n console.assert(JSON.stringify(factorize(2)) === JSON.stringify([2]))\n console.assert(JSON.stringify(factorize(4)) === JSON.stringify([2, 2]))\n console.assert(JSON.stringify(factorize(8)) === JSON.stringify([2, 2, 2]))\n console.assert(JSON.stringify(factorize(3 * 19)) === JSON.stringify([3, 19]))\n console.assert(\n JSON.stringify(factorize(3 * 19 * 3 * 19)) ===\n JSON.stringify([3, 3, 19, 19])\n )\n console.assert(\n JSON.stringify(factorize(3 * 19 * 3 * 19 * 3 * 19)) ===\n JSON.stringify([3, 3, 3, 19, 19, 19])\n )\n console.assert(\n JSON.stringify(factorize(3 * 19 * 19 * 19)) ===\n JSON.stringify([3, 19, 19, 19])\n )\n console.assert(\n JSON.stringify(factorize(3 * 2 * 3)) === JSON.stringify([2, 3, 3])\n )\n}\n\ntestFactorize()\n", "declaration": "\nconst factorize = (n) => {\n", "example_test": "const testFactorize = () => {\n console.assert(JSON.stringify(factorize(8)) === JSON.stringify([2, 2, 2]))\n console.assert(JSON.stringify(factorize(25)) === JSON.stringify([5,5]))\n console.assert(\n JSON.stringify(factorize(70)) ===\n JSON.stringify([2,5,7])\n )\n}\ntestFactorize()\n", "buggy_solution": " var fact = [], i = 0;\n while (i <= Math.sqrt(n) + 1) {\n if (n % i == 0) {\n fact.push(i);\n n = n / i;\n } else {\n i += 1;\n }\n }\n\n if (n > 1)\n fact.push(n);\n return fact;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "factorize", "signature": "const factorize = (n)", "docstring": "Return list of prime factors of given integer in the order from smallest to largest.\nEach of the factors should be listed number of times corresponding to how many times it appeares in factorization.\nInput number should be equal to the product of all factors\n>>> factorize(8)\n[2, 2, 2]\n>>> factorize(25)\n[5, 5]\n>>> factorize(70)\n[2, 5, 7]", "instruction": "Write a JavaScript function `const factorize = (n)` to solve the following problem:\nReturn list of prime factors of given integer in the order from smallest to largest.\nEach of the factors should be listed number of times corresponding to how many times it appeares in factorization.\nInput number should be equal to the product of all factors\n>>> factorize(8)\n[2, 2, 2]\n>>> factorize(25)\n[5, 5]\n>>> factorize(70)\n[2, 5, 7]"} +{"task_id": "JavaScript/26", "prompt": "/* From a list of integers, remove all elements that occur more than once.\n Keep order of elements left the same as in the input.\n >>> removeDuplicates([1, 2, 3, 2, 4])\n [1, 3, 4]\n */\nconst removeDuplicates = (numbers) => {\n", "canonical_solution": " var dict = new Object();\n for (const num of numbers) {\n if (num in dict) {\n dict[num] += 1;\n } else {\n dict[num] = 1;\n }\n }\n return numbers.filter(x => dict[x] <= 1);\n}\n\n", "test": "const testRemoveDuplicates = () => {\n console.assert(JSON.stringify(removeDuplicates([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(removeDuplicates([1, 2, 3, 4])) ===\n JSON.stringify([1, 2, 3, 4])\n )\n console.assert(\n JSON.stringify(removeDuplicates([1, 2, 3, 2, 4, 3, 5])) ===\n JSON.stringify([1, 4, 5])\n )\n}\n\ntestRemoveDuplicates()\n", "declaration": "\nconst removeDuplicates = (numbers) => {\n", "example_test": "const testRemoveDuplicates = () => {\n console.assert(\n JSON.stringify(removeDuplicates([1, 2, 3, 2,4])) ===\n JSON.stringify([1,3, 4])\n )\n}\ntestRemoveDuplicates()\n", "buggy_solution": " var dict = new Object();\n for (const num of numbers) {\n if (num in dict) {\n dict[num] += 1;\n } else {\n dict[num] = 1;\n }\n }\n return numbers.filter(x > dict[x] < 1);\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "removeDuplicates", "signature": "const removeDuplicates = (numbers)", "docstring": "From a list of integers, remove all elements that occur more than once.\nKeep order of elements left the same as in the input.\n>>> removeDuplicates([1, 2, 3, 2, 4])\n[1, 3, 4]", "instruction": "Write a JavaScript function `const removeDuplicates = (numbers)` to solve the following problem:\nFrom a list of integers, remove all elements that occur more than once.\nKeep order of elements left the same as in the input.\n>>> removeDuplicates([1, 2, 3, 2, 4])\n[1, 3, 4]"} +{"task_id": "JavaScript/27", "prompt": "/* For a given string, flip lowercase characters to uppercase and uppercase to lowercase.\n >>> flipCase('Hello')\n 'hELLO'\n */\nconst flipCase = (string) => {\n", "canonical_solution": " return string.split('')\n .map(x => (x.toUpperCase() == x ? x.toLowerCase() : x.toUpperCase()))\n .join('');\n}\n\n", "test": "const testFlipCase = () => {\n console.assert(flipCase('') === '')\n console.assert(flipCase('Hello!') === 'hELLO!')\n console.assert(\n flipCase(\n 'These violent delights have violent ends') ===\n 'tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS'\n )\n}\n\ntestFlipCase()\n", "declaration": "\nconst flipCase = (string) => {\n", "example_test": "const testFlipCase = () => {\n console.assert(flipCase('Hello') === 'hELLO')\n}\ntestFlipCase()\n", "buggy_solution": " return string.split('')\n .map(x => (x.toLowerCase() == x ? x.toLowerCase() : x.toUpperCase()))\n .join('');\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "flipCase", "signature": "const flipCase = (string)", "docstring": "For a given string, flip lowercase characters to uppercase and uppercase to lowercase.\n>>> flipCase('Hello')\n'hELLO'", "instruction": "Write a JavaScript function `const flipCase = (string)` to solve the following problem:\nFor a given string, flip lowercase characters to uppercase and uppercase to lowercase.\n>>> flipCase('Hello')\n'hELLO'"} +{"task_id": "JavaScript/28", "prompt": "/* Concatenate list of strings into a single string\n >>> concatenate([])\n ''\n >>> concatenate(['a', 'b', 'c'])\n 'abc'\n */\nconst concatenate = (strings) => {\n", "canonical_solution": " return strings.join('');\n}\n\n", "test": "const testConcatenate = () => {\n console.assert(concatenate([]) === '')\n console.assert(concatenate(['x', 'y', 'z']) === 'xyz')\n console.assert(concatenate(['x', 'y', 'z', 'w', 'k']) === 'xyzwk')\n}\n\ntestConcatenate()\n", "declaration": "\nconst concatenate = (strings) => {\n", "example_test": "const testConcatenate = () => {\n console.assert(concatenate([]) === '')\n console.assert(concatenate(['a', 'b', 'c']) === 'abc')\n}\ntestConcatenate()\n", "buggy_solution": " return strings.join(' ');\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "concatenate", "signature": "const concatenate = (strings)", "docstring": "Concatenate list of strings into a single string\n>>> concatenate([])\n''\n>>> concatenate(['a', 'b', 'c'])\n'abc'", "instruction": "Write a JavaScript function `const concatenate = (strings)` to solve the following problem:\nConcatenate list of strings into a single string\n>>> concatenate([])\n''\n>>> concatenate(['a', 'b', 'c'])\n'abc'"} +{"task_id": "JavaScript/29", "prompt": "/* Filter an input list of strings only for ones that start with a given prefix.\n >>> filterByPrefix([], 'a')\n []\n >>> filterByPrefix(['abc', 'bcd', 'cde', 'array'], 'a')\n ['abc', 'array']\n */\nconst filterByPrefix = (strings, prefix) => {\n", "canonical_solution": " return strings.filter(x => x.startsWith(prefix));\n}\n\n", "test": "const testFilterByPrefix = () => {\n console.assert(\n JSON.stringify(filterByPrefix([], 'john')) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(\n filterByPrefix(['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'], 'xxx')\n ) === JSON.stringify(['xxx', 'xxxAAA', 'xxx'])\n )\n}\n\ntestFilterByPrefix()\n", "declaration": "\nconst filterByPrefix = (strings, prefix) => {\n", "example_test": "const testFilterByPrefix = () => {\n console.assert(\n JSON.stringify(filterByPrefix([], 'a')) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(\n filterByPrefix(['abc', 'bcd', 'cde', 'array'], 'a')\n ) === JSON.stringify(['abc', 'array'])\n )\n}\ntestFilterByPrefix()\n", "buggy_solution": " return strings.filter(x => x.endsWith(prefix));\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "filterByPrefix", "signature": "const filterByPrefix = (strings, prefix)", "docstring": "Filter an input list of strings only for ones that start with a given prefix.\n>>> filterByPrefix([], 'a')\n[]\n>>> filterByPrefix(['abc', 'bcd', 'cde', 'array'], 'a')\n['abc', 'array']", "instruction": "Write a JavaScript function `const filterByPrefix = (strings, prefix)` to solve the following problem:\nFilter an input list of strings only for ones that start with a given prefix.\n>>> filterByPrefix([], 'a')\n[]\n>>> filterByPrefix(['abc', 'bcd', 'cde', 'array'], 'a')\n['abc', 'array']"} +{"task_id": "JavaScript/30", "prompt": "/*Return only positive numbers in the list.\n >>> getPositive([-1, 2, -4, 5, 6])\n [2, 5, 6]\n >>> getPositive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n [5, 3, 2, 3, 9, 123, 1]\n */\nconst getPositive = (l) => {\n", "canonical_solution": " return l.filter(e => e > 0);\n}\n\n", "test": "const testGetPositive = () => {\n console.assert(\n JSON.stringify(getPositive([-1, -2, 4, 5, 6])) === JSON.stringify([4, 5, 6])\n )\n console.assert(\n JSON.stringify(getPositive([5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10])) ===\n JSON.stringify([5, 3, 2, 3, 3, 9, 123, 1])\n )\n console.assert(JSON.stringify(getPositive([-1, -2])) === JSON.stringify([]))\n console.assert(JSON.stringify(getPositive([])) === JSON.stringify([]))\n}\n\ntestGetPositive()\n", "declaration": "\nconst getPositive = (l) => {\n", "example_test": "const testGetPositive = () => {\n console.assert(\n JSON.stringify(getPositive([-1, 2, -4, 5, 6])) === JSON.stringify([2, 5, 6])\n )\n console.assert(\n JSON.stringify(getPositive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) ===\n JSON.stringify([5, 3, 2, 3, 9, 123, 1])\n )\n}\ntestGetPositive()\n", "buggy_solution": " return l.filter(e => e < 0);\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "getPositive", "signature": "const getPositive = (l)", "docstring": "Return only positive numbers in the list.\n>>> getPositive([-1, 2, -4, 5, 6])\n[2, 5, 6]\n>>> getPositive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n[5, 3, 2, 3, 9, 123, 1]", "instruction": "Write a JavaScript function `const getPositive = (l)` to solve the following problem:\nReturn only positive numbers in the list.\n>>> getPositive([-1, 2, -4, 5, 6])\n[2, 5, 6]\n>>> getPositive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n[5, 3, 2, 3, 9, 123, 1]"} +{"task_id": "JavaScript/31", "prompt": "/*Return true if a given number is prime, and false otherwise.\n >>> isPrime(6)\n false\n >>> isPrime(101)\n true\n >>> isPrime(11)\n true\n >>> isPrime(13441)\n true\n >>> isPrime(61)\n true\n >>> isPrime(4)\n false\n >>> isPrime(1)\n false\n */\nconst isPrime = (n) => {\n", "canonical_solution": " if (n < 2)\n return false;\n for (let k = 2; k < n - 1; k++)\n if (n % k == 0)\n return false;\n return true;\n}\n\n", "test": "const testIsPrime = () => {\n console.assert(isPrime(6) === false)\n console.assert(isPrime(101) === true)\n console.assert(isPrime(11) === true)\n console.assert(isPrime(13441) === true)\n console.assert(isPrime(61) === true)\n console.assert(isPrime(4) === false)\n console.assert(isPrime(1) === false)\n console.assert(isPrime(5) === true)\n console.assert(isPrime(11) === true)\n console.assert(isPrime(17) === true)\n console.assert(isPrime(5 * 17) === false)\n console.assert(isPrime(11 * 7) === false)\n console.assert(isPrime(13441 * 19) === false)\n}\n\ntestIsPrime()\n", "declaration": "\nconst isPrime = (n) => {\n", "example_test": "const testIsPrime = () => {\n console.assert(isPrime(6) === false)\n console.assert(isPrime(101) === true)\n console.assert(isPrime(11) === true)\n console.assert(isPrime(13441) === true)\n console.assert(isPrime(61) === true)\n console.assert(isPrime(4) === false)\n console.assert(isPrime(1) === false)\n}\ntestIsPrime()\n", "buggy_solution": " if (n < 1)\n return false;\n for (let k = 1; k < n - 1; k++)\n if (n % k == 0)\n return false;\n return true;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "isPrime", "signature": "const isPrime = (n)", "docstring": "Return true if a given number is prime, and false otherwise.\n>>> isPrime(6)\nfalse\n>>> isPrime(101)\ntrue\n>>> isPrime(11)\ntrue\n>>> isPrime(13441)\ntrue\n>>> isPrime(61)\ntrue\n>>> isPrime(4)\nfalse\n>>> isPrime(1)\nfalse", "instruction": "Write a JavaScript function `const isPrime = (n)` to solve the following problem:\nReturn true if a given number is prime, and false otherwise.\n>>> isPrime(6)\nfalse\n>>> isPrime(101)\ntrue\n>>> isPrime(11)\ntrue\n>>> isPrime(13441)\ntrue\n>>> isPrime(61)\ntrue\n>>> isPrime(4)\nfalse\n>>> isPrime(1)\nfalse"} +{"task_id": "JavaScript/32", "prompt": "/*\n Evaluates polynomial with coefficients xs at point x.\n return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n\n */\nconst poly = (xs, x) => {\n return xs.reduce((prev, item, index) => {\n return prev + item * Math.pow(x, index);\n }, 0);\n}\n\n/*\n xs are coefficients of a polynomial.\n findZero find x such that poly(x) = 0.\n findZero returns only only zero point, even if there are many.\n Moreover, findZero only takes list xs having even number of coefficients\n and largest non zero coefficient as it guarantees\n a solution.\n >>> round(findZero([1, 2]), 2) # f(x) = 1 + 2x\n -0.5\n >>> round(findZero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3\n 1.0\n */\nconst findZero = (xs) => {\n", "canonical_solution": " var begin = -1.0, end = 1.0;\n while (poly(xs, begin) * poly(xs, end) > 0) {\n begin *= 2.0;\n end *= 2.0;\n }\n while (end - begin > 1e-10) {\n let center = (begin + end) / 2.0;\n if (poly(xs, center) * poly(xs, begin) > 0)\n begin = center;\n else\n end = center;\n }\n return begin;\n}\n\n", "test": "const testfindZero = () => {\n const getRandomIntInclusive = (min = 0, max = 9) => {\n min = Math.ceil(min)\n max = Math.floor(max)\n return Math.floor(Math.random() * (max - min + 1)) + min\n }\n\n for (let i = 0; i < 100; i++) {\n let ncoeff = 2 * getRandomIntInclusive(1, 4);\n let coeffs = [];\n for (let j = 0; j < ncoeff; j++) {\n let coeff = getRandomIntInclusive(-10, 10);\n if (coeff === 0)\n coeff = 1;\n coeffs.push(coeff);\n }\n let solution = findZero(coeffs);\n console.assert(Math.abs(poly(coeffs, solution)) < 1e-4);\n }\n}\ntestfindZero()\n", "declaration": "\nconst poly = (xs, x) => {\n return xs.reduce((prev, item, index) => {\n return prev + item * Math.pow(x, index);\n }, 0);\n}\n\nconst findZero = (xs) => {\n", "example_test": "const testPoly = () => {\n console.assert(Math.abs(findZero([1,2])+0.5 < 1e-4));\n console.assert(Math.abs(findZero([-6,11,-6,1])-1 < 1e-4));\n}\ntestPoly()\n", "buggy_solution": " var begin = -1.0, end = 1.0;\n while (poly(xs, begin) * poly(xs, end) > 0) {\n begin *= 2.0;\n end *= 2.0;\n }\n while (begin - end > 1e-10) {\n let center = (begin + end) / 2.0;\n if (poly(xs, center) * poly(xs, end) > 0)\n begin = center;\n else\n end = center;\n }\n return end;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "findZero", "signature": "const findZero = (xs)", "docstring": "xs are coefficients of a polynomial.\nfindZero find x such that poly(x) = 0.\nfindZero returns only only zero point, even if there are many.\nMoreover, findZero only takes list xs having even number of coefficients\nand largest non zero coefficient as it guarantees\na solution.\n>>> round(findZero([1, 2]), 2) # f(x) = 1 + 2x\n-0.5\n>>> round(findZero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3\n1.0", "instruction": "Write a JavaScript function `const findZero = (xs)` to solve the following problem:\nxs are coefficients of a polynomial.\nfindZero find x such that poly(x) = 0.\nfindZero returns only only zero point, even if there are many.\nMoreover, findZero only takes list xs having even number of coefficients\nand largest non zero coefficient as it guarantees\na solution.\n>>> round(findZero([1, 2]), 2) # f(x) = 1 + 2x\n-0.5\n>>> round(findZero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3\n1.0"} +{"task_id": "JavaScript/33", "prompt": "/*This function takes a list l and returns a list l' such that\n l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal\n to the values of the corresponding indicies of l, but sorted.\n >>> sortThird([1, 2, 3])\n [1, 2, 3]\n >>> sortThird([5, 6, 3, 4, 8, 9, 2])\n [2, 6, 3, 4, 8, 9, 5]\n */\nconst sortThird = (l) => {\n", "canonical_solution": " var three = l.filter((item, index) => index % 3 == 0);\n three.sort((a, b) => (a - b));\n return l.map((item, index) => (index % 3 == 0 ? three[index / 3] : item));\n}\n\n", "test": "const testSortThird = () => {\n console.assert(\n JSON.stringify(sortThird([1, 2, 3])) == JSON.stringify([1, 2, 3])\n )\n console.assert(\n JSON.stringify(sortThird([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) ==\n JSON.stringify([1, 3, -5, 2, -3, 3, 5, 0, 123, 9, -10])\n )\n console.assert(\n JSON.stringify(sortThird([5, 8, -12, 4, 23, 2, 3, 11, 12, -10])) ==\n JSON.stringify([-10, 8, -12, 3, 23, 2, 4, 11, 12, 5])\n )\n console.assert(\n JSON.stringify(sortThird([5, 6, 3, 4, 8, 9, 2])) ==\n JSON.stringify([2, 6, 3, 4, 8, 9, 5])\n )\n console.assert(\n JSON.stringify(sortThird([5, 8, 3, 4, 6, 9, 2])) ==\n JSON.stringify([2, 8, 3, 4, 6, 9, 5])\n )\n console.assert(\n JSON.stringify(sortThird([5, 6, 9, 4, 8, 3, 2])) ==\n JSON.stringify([2, 6, 9, 4, 8, 3, 5])\n )\n console.assert(\n JSON.stringify(sortThird([5, 6, 3, 4, 8, 9, 2, 1])) ==\n JSON.stringify([2, 6, 3, 4, 8, 9, 5, 1])\n )\n}\n\ntestSortThird()\n", "declaration": "\nconst sortThird = (l) => {\n", "example_test": "const testSortThird = () => {\n console.assert(\n JSON.stringify(sortThird([1, 2, 3])) == JSON.stringify([1, 2, 3])\n )\n console.assert(\n JSON.stringify(sortThird([5, 6, 3, 4, 8, 9, 2])) ==\n JSON.stringify([2, 6, 3, 4, 8, 9, 5])\n )\n}\ntestSortThird()\n", "buggy_solution": " var three = l.filter((item, index) => index % 3 == 0);\n return l.map((item, index) => (index % 2 == 0 ? three[index / 3] : item));\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sortThird", "signature": "const sortThird = (l)", "docstring": "This function takes a list l and returns a list l' such that\nl' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal\nto the values of the corresponding indicies of l, but sorted.\n>>> sortThird([1, 2, 3])\n[1, 2, 3]\n>>> sortThird([5, 6, 3, 4, 8, 9, 2])\n[2, 6, 3, 4, 8, 9, 5]", "instruction": "Write a JavaScript function `const sortThird = (l)` to solve the following problem:\nThis function takes a list l and returns a list l' such that\nl' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal\nto the values of the corresponding indicies of l, but sorted.\n>>> sortThird([1, 2, 3])\n[1, 2, 3]\n>>> sortThird([5, 6, 3, 4, 8, 9, 2])\n[2, 6, 3, 4, 8, 9, 5]"} +{"task_id": "JavaScript/34", "prompt": "/*Return sorted unique elements in a list\n >>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123])\n [0, 2, 3, 5, 9, 123]\n */\nconst unique = (l) => {\n", "canonical_solution": " return Array.from(new Set(l)).sort((a, b) => (a - b));\n}\n\n", "test": "const testUnique = () => {\n console.assert(\n JSON.stringify(unique([5, 3, 5, 2, 3, 3, 9, 0, 123])) ===\n JSON.stringify([0, 2, 3, 5, 9, 123])\n )\n}\n\ntestUnique()\n", "declaration": "\nconst unique = (l) => {\n", "example_test": "const testUnique = () => {\n console.assert(\n JSON.stringify(unique([5, 3, 5, 2, 3, 3, 9, 0, 123])) ===\n JSON.stringify([0, 2, 3, 5, 9, 123])\n )\n}\ntestUnique()\n", "buggy_solution": " return l.sort((a, b) => (a - b));\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "unique", "signature": "const unique = (l)", "docstring": "Return sorted unique elements in a list\n>>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123])\n[0, 2, 3, 5, 9, 123]", "instruction": "Write a JavaScript function `const unique = (l)` to solve the following problem:\nReturn sorted unique elements in a list\n>>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123])\n[0, 2, 3, 5, 9, 123]"} +{"task_id": "JavaScript/35", "prompt": "/*Return maximum element in the list.\n >>> maxElement([1, 2, 3])\n 3\n >>> maxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n 123\n */\nconst maxElement = (l) => {\n", "canonical_solution": " return Math.max(...l);\n}\n\n", "test": "const testMaxElement = () => {\n console.assert(maxElement([1, 2, 3]) === 3)\n console.assert(maxElement([5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10]) === 124)\n}\n\ntestMaxElement()\n", "declaration": "\nconst maxElement = (l) => {\n", "example_test": "const testMaxElement = () => {\n console.assert(maxElement([1, 2, 3]) === 3)\n console.assert(maxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) === 123)\n}\ntestMaxElement()\n", "buggy_solution": " return Math.min(...l);\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "maxElement", "signature": "const maxElement = (l)", "docstring": "Return maximum element in the list.\n>>> maxElement([1, 2, 3])\n3\n>>> maxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n123", "instruction": "Write a JavaScript function `const maxElement = (l)` to solve the following problem:\nReturn maximum element in the list.\n>>> maxElement([1, 2, 3])\n3\n>>> maxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n123"} +{"task_id": "JavaScript/36", "prompt": "/*Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.\n >>> fizzBuzz(50)\n 0\n >>> fizzBuzz(78)\n 2\n >>> fizzBuzz(79)\n 3\n */\nconst fizzBuzz = (n) => {\n", "canonical_solution": " var ns = [], ans = 0;\n for (let i = 0; i < n; i++)\n if (i % 11 == 0 || i % 13 == 0)\n ns.push(i);\n var s = ns.map(x => x.toString()).join('');\n for (const c of s)\n ans += (c == '7');\n return ans;\n}\n\n", "test": "const testFizzBuzz = () => {\n console.assert(fizzBuzz(50) === 0)\n console.assert(fizzBuzz(78) === 2)\n console.assert(fizzBuzz(79) === 3)\n console.assert(fizzBuzz(100) === 3)\n console.assert(fizzBuzz(200) === 6)\n console.assert(fizzBuzz(4000) === 192)\n console.assert(fizzBuzz(10000) === 639)\n console.assert(fizzBuzz(100000) === 8026)\n}\n\ntestFizzBuzz()\n", "declaration": "\nconst fizzBuzz = (n) => {\n", "example_test": "const testFizzBuzz = () => {\n console.assert(fizzBuzz(50) === 0)\n console.assert(fizzBuzz(78) === 2)\n console.assert(fizzBuzz(79) === 3)\n}\ntestFizzBuzz()\n", "buggy_solution": " var ns = [], ans = 0;\n for (let i = 0; i < n; i++)\n if (i % 11 == 0 && i % 13 == 0)\n ns.push(i);\n var s = ns.map(x => x.toString()).join('');\n for (const c of s)\n ans += (c == '7');\n return ans;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "fizzBuzz", "signature": "const fizzBuzz = (n)", "docstring": "Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.\n>>> fizzBuzz(50)\n0\n>>> fizzBuzz(78)\n2\n>>> fizzBuzz(79)\n3", "instruction": "Write a JavaScript function `const fizzBuzz = (n)` to solve the following problem:\nReturn the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.\n>>> fizzBuzz(50)\n0\n>>> fizzBuzz(78)\n2\n>>> fizzBuzz(79)\n3"} +{"task_id": "JavaScript/37", "prompt": "/*This function takes a list l and returns a list l' such that\n l' is identical to l in the odd indicies, while its values at the even indicies are equal\n to the values of the even indicies of l, but sorted.\n >>> sortEven([1, 2, 3])\n [1, 2, 3]\n >>> sortEven([5, 6, 3, 4])\n [3, 6, 5, 4]\n */\nconst sortEven = (l) => {\n", "canonical_solution": " var even = l.filter((item, index) => index % 2 == 0);\n even.sort((a, b) => (a - b));\n return l.map((item, index) => (index % 2 == 0 ? even[index / 2] : item));\n}\n\n", "test": "const testSortEven = () => {\n console.assert(JSON.stringify(sortEven([1, 2, 3])) ===\n JSON.stringify([1, 2, 3]))\n console.assert(JSON.stringify(\n sortEven([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) ===\n JSON.stringify([-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123]))\n console.assert(JSON.stringify(\n sortEven([5, 8, -12, 4, 23, 2, 3, 11, 12, -10])) ===\n JSON.stringify([-12, 8, 3, 4, 5, 2, 12, 11, 23, -10]))\n}\n\ntestSortEven()\n", "declaration": "\nconst sortEven = (l) => {\n", "example_test": "const testSortEven = () => {\n console.assert(JSON.stringify(sortEven([1, 2, 3])) ===\n JSON.stringify([1, 2, 3]))\n console.assert(JSON.stringify(\n sortEven([5,6,3,4])) ===\n JSON.stringify([3,6,5,4]))\n}\ntestSortEven()\n", "buggy_solution": " var even = l.filter((item, index) => index % 2 == 0);\n l.sort((a, b) => (a - b));\n return l.map((item, index) => (index % 2 == 0 ? even[index / 2] : item));\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "sortEven", "signature": "const sortEven = (l)", "docstring": "This function takes a list l and returns a list l' such that\nl' is identical to l in the odd indicies, while its values at the even indicies are equal\nto the values of the even indicies of l, but sorted.\n>>> sortEven([1, 2, 3])\n[1, 2, 3]\n>>> sortEven([5, 6, 3, 4])\n[3, 6, 5, 4]", "instruction": "Write a JavaScript function `const sortEven = (l)` to solve the following problem:\nThis function takes a list l and returns a list l' such that\nl' is identical to l in the odd indicies, while its values at the even indicies are equal\nto the values of the even indicies of l, but sorted.\n>>> sortEven([1, 2, 3])\n[1, 2, 3]\n>>> sortEven([5, 6, 3, 4])\n[3, 6, 5, 4]"} +{"task_id": "JavaScript/38", "prompt": "/*\n returns encoded string by cycling groups of three characters.\n */\nconst encodeCyclic = (s) => {\n var groups = [], groups2 = [];\n for (let i = 0; i < Math.floor((s.length + 2) / 3); i++) {\n groups.push(s.slice(3 * i, Math.min((3 * i + 3), s.length)));\n }\n for (const group of groups) {\n if (group.length == 3)\n groups2.push(group.slice(1) + group[0]);\n else\n groups2.push(group);\n }\n return groups2.join('');\n}\n\n/*\n takes as input string encoded with encode_cyclic function. Returns decoded string.\n */\nconst decodeCyclic = (s) => {\n", "canonical_solution": " return encodeCyclic(encodeCyclic(s));\n}\n\n", "test": "const testDecodeCyclic = () => {\n const letters = new Array(26)\n .fill(null)\n .map((v, i) => String.fromCharCode(97 + i));\n\n for (let i = 0; i < 100; i++) {\n let str = new Array(Math.floor(Math.random() * 20)).fill(null);\n str = str.map(item => letters[Math.floor(Math.random() * letters.length)]).join('');\n let encoded_str = encodeCyclic(str);\n console.assert(decodeCyclic(encoded_str) === str);\n }\n}\n\ntestDecodeCyclic()\n", "declaration": "const encodeCyclic = (s) => {\n var groups = [], groups2 = [];\n for (let i = 0; i < Math.floor((s.length + 2) / 3); i++) {\n groups.push(s.slice(3 * i, Math.min((3 * i + 3), s.length)));\n }\n for (const group of groups) {\n if (group.length == 3)\n groups2.push(group.slice(1) + group[0]);\n else\n groups2.push(group);\n }\n return groups2.join('');\n}\n\nconst decodeCyclic = (s) => {\n", "example_test": "", "buggy_solution": " return encodeCyclic(s);\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "decodeCyclic", "signature": "const decodeCyclic = (s)", "docstring": "takes as input string encoded with encode_cyclic function. Returns decoded string.", "instruction": "Write a JavaScript function `const decodeCyclic = (s)` to solve the following problem:\ntakes as input string encoded with encode_cyclic function. Returns decoded string."} +{"task_id": "JavaScript/39", "prompt": "/*\n primeFib returns n-th number that is a Fibonacci number and it's also prime.\n >>> primeFib(1)\n 2\n >>> primeFib(2)\n 3\n >>> primeFib(3)\n 5\n >>> primeFib(4)\n 13\n >>> primeFib(5)\n 89\n */\nconst primeFib = (n) => {\n", "canonical_solution": " var isPrime = function (p) {\n if (p < 2)\n return false;\n for (let k = 2; k < Math.min(Math.floor(Math.sqrt(p)) + 1, p - 1); k++) {\n if (p % k == 0)\n return false;\n }\n return true;\n }\n\n var f = [0, 1];\n while (true) {\n f.push(f.at(-1) + f.at(-2));\n if (isPrime(f.at(-1)))\n n -= 1;\n if (n == 0)\n return f.at(-1);\n }\n}\n\n", "test": "const testPrimeFib = () => {\n console.assert(primeFib(1) === 2)\n console.assert(primeFib(2) === 3)\n console.assert(primeFib(3) === 5)\n console.assert(primeFib(4) === 13)\n console.assert(primeFib(5) === 89)\n console.assert(primeFib(6) === 233)\n console.assert(primeFib(7) === 1597)\n console.assert(primeFib(8) === 28657)\n console.assert(primeFib(9) === 514229)\n console.assert(primeFib(10) === 433494437)\n}\n\ntestPrimeFib()\n", "declaration": "\nconst primeFib = (n) => {\n", "example_test": "const testPrimeFib = () => {\n console.assert(primeFib(1) === 2)\n console.assert(primeFib(2) === 3)\n console.assert(primeFib(3) === 5)\n console.assert(primeFib(4) === 13)\n console.assert(primeFib(5) === 89)\n}\ntestPrimeFib()\n", "buggy_solution": " var isPrime = function (p) {\n if (p < 2)\n return false;\n for (let k = 2; k < Math.min(Math.floor(Math.sqrt(p)), p); k++) {\n if (p % k == 0)\n return false;\n }\n return true;\n }\n\n var f = [0, 1];\n while (true) {\n f.push(f.at(-1) + f.at(-2));\n if (isPrime(f.at(-1)))\n n -= 1;\n if (n == 0)\n return f.at(-1);\n }\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "primeFib", "signature": "const primeFib = (n)", "docstring": "primeFib returns n-th number that is a Fibonacci number and it's also prime.\n>>> primeFib(1)\n2\n>>> primeFib(2)\n3\n>>> primeFib(3)\n5\n>>> primeFib(4)\n13\n>>> primeFib(5)\n89", "instruction": "Write a JavaScript function `const primeFib = (n)` to solve the following problem:\nprimeFib returns n-th number that is a Fibonacci number and it's also prime.\n>>> primeFib(1)\n2\n>>> primeFib(2)\n3\n>>> primeFib(3)\n5\n>>> primeFib(4)\n13\n>>> primeFib(5)\n89"} +{"task_id": "JavaScript/40", "prompt": "/*\n triplesSumToZero takes a list of integers as an input.\n it returns true if there are three distinct elements in the list that\n sum to zero, and false otherwise.\n\n >>> triplesSumToZero([1, 3, 5, 0])\n false\n >>> triplesSumToZero([1, 3, -2, 1])\n true\n >>> triplesSumToZero([1, 2, 3, 7])\n false\n >>> triplesSumToZero([2, 4, -5, 3, 9, 7])\n true\n >>> triplesSumToZero([1])\n false\n */\nconst triplesSumToZero = (l) => {\n", "canonical_solution": " for (let i = 0; i < l.length; i++)\n for (let j = i + 1; j < l.length; j++)\n for (let k = j + 1; k < l.length; k++)\n if (l[i] + l[j] + l[k] == 0)\n return true;\n return false;\n}\n\n", "test": "const testTriplesSumToZero = () => {\n console.assert(triplesSumToZero([1, 3, 5, 0]) === false)\n console.assert(triplesSumToZero([1, 3, 5, -1]) === false)\n console.assert(triplesSumToZero([1, 3, -2, 1]) === true)\n console.assert(triplesSumToZero([1, 2, 3, 7]) === false)\n console.assert(triplesSumToZero([1, 2, 5, 7]) === false)\n console.assert(triplesSumToZero([2, 4, -5, 3, 9, 7]) === true)\n console.assert(triplesSumToZero([1]) === false)\n console.assert(triplesSumToZero([1, 3, 5, -100]) === false)\n console.assert(triplesSumToZero([100, 3, 5, -100]) === false)\n}\n\ntestTriplesSumToZero()\n", "declaration": "\nconst triplesSumToZero = (l) => {\n", "example_test": "const testTriplesSumToZero = () => {\n console.assert(triplesSumToZero([1, 3, 5, 0]) === false)\n console.assert(triplesSumToZero([1, 3, -2, 1]) === true)\n console.assert(triplesSumToZero([1, 2, 3, 7]) === false)\n console.assert(triplesSumToZero([2, 4, -5, 3, 9, 7]) === true)\n}\ntestTriplesSumToZero()\n", "buggy_solution": " for (let i = 1; i < l.length; i++)\n for (let j = i + 1; j < l.length; j++)\n for (let k = j + 1; k < l.length; k++)\n if (l[i] + l[j] + l[k] == 0)\n return true;\n return false;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "triplesSumToZero", "signature": "const triplesSumToZero = (l)", "docstring": "triplesSumToZero takes a list of integers as an input.\nit returns true if there are three distinct elements in the list that\nsum to zero, and false otherwise.\n>>> triplesSumToZero([1, 3, 5, 0])\nfalse\n>>> triplesSumToZero([1, 3, -2, 1])\ntrue\n>>> triplesSumToZero([1, 2, 3, 7])\nfalse\n>>> triplesSumToZero([2, 4, -5, 3, 9, 7])\ntrue\n>>> triplesSumToZero([1])\nfalse", "instruction": "Write a JavaScript function `const triplesSumToZero = (l)` to solve the following problem:\ntriplesSumToZero takes a list of integers as an input.\nit returns true if there are three distinct elements in the list that\nsum to zero, and false otherwise.\n>>> triplesSumToZero([1, 3, 5, 0])\nfalse\n>>> triplesSumToZero([1, 3, -2, 1])\ntrue\n>>> triplesSumToZero([1, 2, 3, 7])\nfalse\n>>> triplesSumToZero([2, 4, -5, 3, 9, 7])\ntrue\n>>> triplesSumToZero([1])\nfalse"} +{"task_id": "JavaScript/41", "prompt": "/*\n Imagine a road that's a perfectly straight infinitely long line.\n n cars are driving left to right; simultaneously, a different set of n cars\n are driving right to left. The two sets of cars start out being very far from\n each other. All cars move in the same speed. Two cars are said to collide\n when a car that's moving left to right hits a car that's moving right to left.\n However, the cars are infinitely sturdy and strong; as a result, they continue moving\n in their trajectory as if they did not collide.\n\n This function outputs the number of such collisions.\n */\nconst carRaceCollision = (n) => {\n", "canonical_solution": " return Math.pow(n, 2);\n}\n\n", "test": "const testCarRaceCollision = () => {\n console.assert(carRaceCollision(2) === 4)\n console.assert(carRaceCollision(3) === 9)\n console.assert(carRaceCollision(4) === 16)\n console.assert(carRaceCollision(8) === 64)\n console.assert(carRaceCollision(10) === 100)\n}\n\ntestCarRaceCollision()\n", "declaration": "\nconst carRaceCollision = (n) => {\n", "example_test": "", "buggy_solution": " return Math.pow(n, 3);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "carRaceCollision", "signature": "const carRaceCollision = (n)", "docstring": "Imagine a road that's a perfectly straight infinitely long line.\nn cars are driving left to right; simultaneously, a different set of n cars\nare driving right to left. The two sets of cars start out being very far from\neach other. All cars move in the same speed. Two cars are said to collide\nwhen a car that's moving left to right hits a car that's moving right to left.\nHowever, the cars are infinitely sturdy and strong; as a result, they continue moving\nin their trajectory as if they did not collide.\nThis function outputs the number of such collisions.", "instruction": "Write a JavaScript function `const carRaceCollision = (n)` to solve the following problem:\nImagine a road that's a perfectly straight infinitely long line.\nn cars are driving left to right; simultaneously, a different set of n cars\nare driving right to left. The two sets of cars start out being very far from\neach other. All cars move in the same speed. Two cars are said to collide\nwhen a car that's moving left to right hits a car that's moving right to left.\nHowever, the cars are infinitely sturdy and strong; as a result, they continue moving\nin their trajectory as if they did not collide.\nThis function outputs the number of such collisions."} +{"task_id": "JavaScript/42", "prompt": "/*Return list with elements incremented by 1.\n >>> incrList([1, 2, 3])\n [2, 3, 4]\n >>> incrList([5, 3, 5, 2, 3, 3, 9, 0, 123])\n [6, 4, 6, 3, 4, 4, 10, 1, 124]\n */\nconst incrList = (l) => {\n", "canonical_solution": " return l.map(e => e + 1);\n}\n\n", "test": "const testIncrList = () => {\n console.assert(JSON.stringify(incrList([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(incrList([3, 2, 1])) === JSON.stringify([4, 3, 2])\n )\n console.assert(\n JSON.stringify(incrList([5, 2, 5, 2, 3, 3, 9, 0, 123])) ===\n JSON.stringify([6, 3, 6, 3, 4, 4, 10, 1, 124])\n )\n}\n\ntestIncrList()\n", "declaration": "\nconst incrList = (l) => {\n", "example_test": "const testIncrList = () => {\n console.assert(\n JSON.stringify(incrList([1, 2, 3])) === JSON.stringify([2, 3, 4])\n )\n console.assert(\n JSON.stringify(incrList([5, 2, 5, 2, 3, 3, 9, 0, 123])) ===\n JSON.stringify([6, 3, 6, 3, 4, 4, 10, 1, 124])\n )\n}\ntestIncrList()\n", "buggy_solution": " return l.map(e => e + 2);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "incrList", "signature": "const incrList = (l)", "docstring": "Return list with elements incremented by 1.\n>>> incrList([1, 2, 3])\n[2, 3, 4]\n>>> incrList([5, 3, 5, 2, 3, 3, 9, 0, 123])\n[6, 4, 6, 3, 4, 4, 10, 1, 124]", "instruction": "Write a JavaScript function `const incrList = (l)` to solve the following problem:\nReturn list with elements incremented by 1.\n>>> incrList([1, 2, 3])\n[2, 3, 4]\n>>> incrList([5, 3, 5, 2, 3, 3, 9, 0, 123])\n[6, 4, 6, 3, 4, 4, 10, 1, 124]"} +{"task_id": "JavaScript/43", "prompt": "/*\n pairsSumToZero takes a list of integers as an input.\n it returns true if there are two distinct elements in the list that\n sum to zero, and false otherwise.\n >>> pairsSumToZero([1, 3, 5, 0])\n false\n >>> pairsSumToZero([1, 3, -2, 1])\n false\n >>> pairsSumToZero([1, 2, 3, 7])\n false\n >>> pairsSumToZero([2, 4, -5, 3, 5, 7])\n true\n >>> pairsSumToZero([1])\n false\n */\nconst pairsSumToZero = (l) => {\n", "canonical_solution": " for (let i = 0; i < l.length; i++)\n for (let j = i + 1; j < l.length; j++)\n if (l[i] + l[j] == 0)\n return true;\n return false;\n}\n\n", "test": "const testPairsSumToZero = () => {\n console.assert(pairsSumToZero([1, 3, 5, 0]) === false)\n console.assert(pairsSumToZero([1, 3, -2, 1]) === false)\n console.assert(pairsSumToZero([1, 2, 3, 7]) === false)\n console.assert(pairsSumToZero([2, 4, -5, 3, 5, 7]) === true)\n console.assert(pairsSumToZero([1]) === false)\n console.assert(pairsSumToZero([-3, 9, -1, 3, 2, 30]) === true)\n console.assert(pairsSumToZero([-3, 9, -1, 3, 2, 31]) === true)\n console.assert(pairsSumToZero([-3, 9, -1, 4, 2, 30]) === false)\n console.assert(pairsSumToZero([-3, 9, -1, 4, 2, 31]) === false)\n}\n\ntestPairsSumToZero()\n", "declaration": "\nconst pairsSumToZero = (l) => {\n", "example_test": "const testPairsSumToZero = () => {\n console.assert(pairsSumToZero([1, 3, 5, 0]) === false)\n console.assert(pairsSumToZero([1, 3, -2, 1]) === false)\n console.assert(pairsSumToZero([1, 2, 3, 7]) === false)\n console.assert(pairsSumToZero([2, 4, -5, 3, 5, 7]) === true)\n}\ntestPairsSumToZero()\n", "buggy_solution": " for (let i = 0; i < l.length; i++)\n for (let j = i; j < l.length; j++)\n if (l[i] + l[j] == 0)\n return true;\n return false;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "pairsSumToZero", "signature": "const pairsSumToZero = (l)", "docstring": "pairsSumToZero takes a list of integers as an input.\nit returns true if there are two distinct elements in the list that\nsum to zero, and false otherwise.\n>>> pairsSumToZero([1, 3, 5, 0])\nfalse\n>>> pairsSumToZero([1, 3, -2, 1])\nfalse\n>>> pairsSumToZero([1, 2, 3, 7])\nfalse\n>>> pairsSumToZero([2, 4, -5, 3, 5, 7])\ntrue\n>>> pairsSumToZero([1])\nfalse", "instruction": "Write a JavaScript function `const pairsSumToZero = (l)` to solve the following problem:\npairsSumToZero takes a list of integers as an input.\nit returns true if there are two distinct elements in the list that\nsum to zero, and false otherwise.\n>>> pairsSumToZero([1, 3, 5, 0])\nfalse\n>>> pairsSumToZero([1, 3, -2, 1])\nfalse\n>>> pairsSumToZero([1, 2, 3, 7])\nfalse\n>>> pairsSumToZero([2, 4, -5, 3, 5, 7])\ntrue\n>>> pairsSumToZero([1])\nfalse"} +{"task_id": "JavaScript/44", "prompt": "/*Change numerical base of input number x to base.\n return string representation after the conversion.\n base numbers are less than 10.\n >>> changeBase(8, 3)\n '22'\n >>> changeBase(8, 2)\n '1000'\n >>> changeBase(7, 2)\n '111'\n */\nconst changeBase = (x, base) => {\n", "canonical_solution": " var ret = \"\";\n while (x > 0) {\n ret = (x % base).toString() + ret;\n x = Math.floor(x / base);\n }\n return ret;\n}\n\n", "test": "const testChangeBase = () => {\n console.assert(changeBase(8, 3) === '22')\n console.assert(changeBase(9, 3) === '100')\n console.assert(changeBase(234, 2) === '11101010')\n console.assert(changeBase(16, 2) === '10000')\n console.assert(changeBase(8, 2) === '1000')\n console.assert(changeBase(7, 2) === '111')\n\n for (let i = 2; i < 8; i++) {\n console.assert(changeBase(i, i + 1) === i.toString())\n }\n}\n\ntestChangeBase()\n", "declaration": "\nconst changeBase = (x, base) => {\n", "example_test": "const testChangeBase = () => {\n console.assert(changeBase(8, 3) === '22')\n console.assert(changeBase(8, 2) === '1000')\n console.assert(changeBase(7, 2) === '111')\n}\ntestChangeBase()\n", "buggy_solution": " var ret = \"\";\n while (x > 0) {\n ret = (x % base).toString() + ret;\n x = Math.floor(x - base);\n }\n return ret;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "infinite loop", "entry_point": "changeBase", "signature": "const changeBase = (x, base)", "docstring": "Change numerical base of input number x to base.\nreturn string representation after the conversion.\nbase numbers are less than 10.\n>>> changeBase(8, 3)\n'22'\n>>> changeBase(8, 2)\n'1000'\n>>> changeBase(7, 2)\n'111'", "instruction": "Write a JavaScript function `const changeBase = (x, base)` to solve the following problem:\nChange numerical base of input number x to base.\nreturn string representation after the conversion.\nbase numbers are less than 10.\n>>> changeBase(8, 3)\n'22'\n>>> changeBase(8, 2)\n'1000'\n>>> changeBase(7, 2)\n'111'"} +{"task_id": "JavaScript/45", "prompt": "/*Given length of a side and high return area for a triangle.\n >>> triangleArea(5, 3)\n 7.5\n */\nconst triangleArea = (a, h) => {\n", "canonical_solution": " return a * h / 2.0;\n}\n\n", "test": "const testTriangleArea = () => {\n console.assert(triangleArea(5, 3) === 7.5)\n console.assert(triangleArea(2, 2) === 2.0)\n console.assert(triangleArea(10, 8) === 40.0)\n}\n\ntestTriangleArea()\n", "declaration": "\nconst triangleArea = (a, h) => {\n", "example_test": "const testTriangleArea = () => {\n console.assert(triangleArea(5, 3) === 7.5)\n}\ntestTriangleArea()\n", "buggy_solution": " return a * h / 0.5;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "triangleArea", "signature": "const triangleArea = (a, h)", "docstring": "Given length of a side and high return area for a triangle.\n>>> triangleArea(5, 3)\n7.5", "instruction": "Write a JavaScript function `const triangleArea = (a, h)` to solve the following problem:\nGiven length of a side and high return area for a triangle.\n>>> triangleArea(5, 3)\n7.5"} +{"task_id": "JavaScript/46", "prompt": "/*The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\n fib4(0) -> 0\n fib4(1) -> 0\n fib4(2) -> 2\n fib4(3) -> 0\n fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).\n Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.\n >>> fib4(5)\n 4\n >>> fib4(6)\n 8\n >>> fib4(7)\n 14\n */\nconst fib4 = (n) => {\n", "canonical_solution": " var results = [0, 0, 2, 0];\n if (n < 4)\n return results[n];\n for (let i = 4; i < n + 1; i++) {\n results.push(results.at(-1) + results.at(-2) +\n results.at(-3) + results.at(-4));\n results.shift();\n }\n return results.pop();\n}\n\n", "test": "const testFib4 = () => {\n console.assert(fib4(5) === 4)\n console.assert(fib4(8) === 28)\n console.assert(fib4(10) === 104)\n console.assert(fib4(12) === 386)\n}\n\ntestFib4()\n", "declaration": "\nconst fib4 = (n) => {\n", "example_test": "const testFib4 = () => {\n console.assert(fib4(5) === 4)\n console.assert(fib4(6) === 8)\n console.assert(fib4(7) === 14)\n}\ntestFib4()\n", "buggy_solution": " var results = [0, 0, 2, 0];\n if (n < 4)\n return results[n];\n for (let i = 4; i < n + 1; i++) {\n results.push(results.at(-1) + results.at(-2) +\n results.at(-3) + results.at(-4));\n results.shift();\n }\n return results.at(-2);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "fib4", "signature": "const fib4 = (n)", "docstring": "The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\nfib4(0) -> 0\nfib4(1) -> 0\nfib4(2) -> 2\nfib4(3) -> 0\nfib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).\nPlease write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.\n>>> fib4(5)\n4\n>>> fib4(6)\n8\n>>> fib4(7)\n14", "instruction": "Write a JavaScript function `const fib4 = (n)` to solve the following problem:\nThe Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\nfib4(0) -> 0\nfib4(1) -> 0\nfib4(2) -> 2\nfib4(3) -> 0\nfib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).\nPlease write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.\n>>> fib4(5)\n4\n>>> fib4(6)\n8\n>>> fib4(7)\n14"} +{"task_id": "JavaScript/47", "prompt": "/*Return median of elements in the list l.\n >>> median([3, 1, 2, 4, 5])\n 3\n >>> median([-10, 4, 6, 1000, 10, 20])\n 8.0\n */\nconst median = (l) => {\n", "canonical_solution": " l.sort((a, b) => a - b);\n var len = l.length;\n if (l.length % 2 == 1)\n return l[Math.floor(len / 2)];\n else\n return (l[len / 2 - 1] + l[len / 2]) / 2.0;\n}\n\n", "test": "const testMedian = () => {\n console.assert(median([3, 1, 2, 4, 5]) === 3)\n console.assert(median([-10, 4, 6, 1000, 10, 20]) === 8.0)\n console.assert(median([5]) === 5)\n console.assert(median([6, 5]) === 5.5)\n console.assert(median([8, 1, 3, 9, 9, 2, 7]) === 7)\n}\n\ntestMedian()\n", "declaration": "\nconst median = (l) => {\n", "example_test": "const testMedian = () => {\n console.assert(median([3, 1, 2, 4, 5]) === 3)\n console.assert(median([-10, 4, 6, 1000, 10, 20]) === 8.0)\n}\ntestMedian()\n", "buggy_solution": " l.sort((a, b) => a - b);\n var len = l.length;\n if (l.length % 2 == 1)\n return l[Math.floor(len / 2)];\n else\n return (l[len - 1 / 2] + l[len / 2]) / 2.0;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "median", "signature": "const median = (l)", "docstring": "Return median of elements in the list l.\n>>> median([3, 1, 2, 4, 5])\n3\n>>> median([-10, 4, 6, 1000, 10, 20])\n8.0", "instruction": "Write a JavaScript function `const median = (l)` to solve the following problem:\nReturn median of elements in the list l.\n>>> median([3, 1, 2, 4, 5])\n3\n>>> median([-10, 4, 6, 1000, 10, 20])\n8.0"} +{"task_id": "JavaScript/48", "prompt": "/*\n Checks if given string is a palindrome\n >>> isPalindrome('')\n true\n >>> isPalindrome('aba')\n true\n >>> isPalindrome('aaaaa')\n true\n >>> isPalindrome('zbcd')\n false\n */\nconst isPalindrome = (text) => {\n", "canonical_solution": " for (let i = 0; i < text.length; i++)\n if (text[i] != text.at(-i-1))\n return false;\n return true;\n}\n\n", "test": "const testIsPalindrome = () => {\n console.assert(isPalindrome('') === true)\n console.assert(isPalindrome('aba') === true)\n console.assert(isPalindrome('aaaaa') === true)\n console.assert(isPalindrome('zbcd') === false)\n console.assert(isPalindrome('xywyx') === true)\n console.assert(isPalindrome('xywyz') === false)\n console.assert(isPalindrome('xywzx') === false)\n}\n\ntestIsPalindrome()\n", "declaration": "\nconst isPalindrome = (text) => {\n", "example_test": "const testIsPalindrome = () => {\n console.assert(isPalindrome('') === true)\n console.assert(isPalindrome('aba') === true)\n console.assert(isPalindrome('aaaaa') === true)\n console.assert(isPalindrome('zbcd') === false)\n}\ntestIsPalindrome()\n", "buggy_solution": " for (let i = 0; i < text.length; i++)\n if (text[i] != text.at(-i))\n return false;\n return true;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "isPalindrome", "signature": "const isPalindrome = (text)", "docstring": "Checks if given string is a palindrome\n>>> isPalindrome('')\ntrue\n>>> isPalindrome('aba')\ntrue\n>>> isPalindrome('aaaaa')\ntrue\n>>> isPalindrome('zbcd')\nfalse", "instruction": "Write a JavaScript function `const isPalindrome = (text)` to solve the following problem:\nChecks if given string is a palindrome\n>>> isPalindrome('')\ntrue\n>>> isPalindrome('aba')\ntrue\n>>> isPalindrome('aaaaa')\ntrue\n>>> isPalindrome('zbcd')\nfalse"} +{"task_id": "JavaScript/49", "prompt": "/*Return 2^n modulo p (be aware of numerics).\n >>> modp(3, 5)\n 3\n >>> modp(1101, 101)\n 2\n >>> modp(0, 101)\n 1\n >>> modp(3, 11)\n 8\n >>> modp(100, 101)\n 1\n */\nconst modp = (n, p) => {\n", "canonical_solution": " var ret = 1;\n for (let i = 0; i < n; i++)\n ret = (2 * ret) % p;\n return ret;\n}\n\n", "test": "const testModp = () => {\n console.assert(modp(3, 5) === 3)\n console.assert(modp(1101, 101) === 2)\n console.assert(modp(0, 101) === 1)\n console.assert(modp(3, 11) === 8)\n console.assert(modp(100, 101) === 1)\n console.assert(modp(30, 5) === 4)\n console.assert(modp(31, 5) === 3)\n}\n\ntestModp()\n", "declaration": "\nconst modp = (n, p) => {\n", "example_test": "const testModp = () => {\n console.assert(modp(3, 5) === 3)\n console.assert(modp(1101, 101) === 2)\n console.assert(modp(0, 101) === 1)\n console.assert(modp(3, 11) === 8)\n console.assert(modp(100, 101) === 1)\n}\ntestModp()\n", "buggy_solution": " var ret = 0;\n for (let i = 0; i < n; i++)\n ret = (2 * ret) % p;\n return ret;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "modp", "signature": "const modp = (n, p)", "docstring": "Return 2^n modulo p (be aware of numerics).\n>>> modp(3, 5)\n3\n>>> modp(1101, 101)\n2\n>>> modp(0, 101)\n1\n>>> modp(3, 11)\n8\n>>> modp(100, 101)\n1", "instruction": "Write a JavaScript function `const modp = (n, p)` to solve the following problem:\nReturn 2^n modulo p (be aware of numerics).\n>>> modp(3, 5)\n3\n>>> modp(1101, 101)\n2\n>>> modp(0, 101)\n1\n>>> modp(3, 11)\n8\n>>> modp(100, 101)\n1"} +{"task_id": "JavaScript/50", "prompt": "/*\n returns encoded string by shifting every character by 5 in the alphabet.\n */\nconst encodeShift = (s) => {\n return s.split(\"\").map(ch => String.fromCharCode(\n ((ch.charCodeAt(0) + 5 - \"a\".charCodeAt(0)) % 26) + \"a\".charCodeAt(0)\n )).join(\"\");\n}\n\n/*\n takes as input string encoded with encode_shift function. Returns decoded string.\n */\nconst decodeShift = (s) => {\n", "canonical_solution": " return s.split(\"\").map(ch => String.fromCharCode(\n ((ch.charCodeAt(0) - 5 + 26 - \"a\".charCodeAt(0)) % 26) + \"a\".charCodeAt(0)\n )).join(\"\");\n}\n\n", "test": "const testDecodeShift = () => {\n const letters = new Array(26)\n .fill(null)\n .map((v, i) => String.fromCharCode(97 + i))\n\n for (let i = 0; i < 100; i++) {\n let str = new Array(Math.floor(Math.random() * 20)).fill(null);\n str = str.map(item => letters[Math.floor(Math.random() * letters.length)]).join('');\n let encoded_str = encodeShift(str)\n console.assert(decodeShift(encoded_str) === str)\n }\n\n}\n\ntestDecodeShift()\n", "declaration": "const encodeShift = (s) => {\n return s.split(\"\").map(ch => String.fromCharCode(\n ((ch.charCodeAt(0) + 5 - \"a\".charCodeAt(0)) % 26) + \"a\".charCodeAt(0)\n )).join(\"\");\n}\n\nconst decodeShift = (s) => {\n", "example_test": "", "buggy_solution": " return s.split(\"\").map(ch => String.fromCharCode(\n ((ch.charCodeAt(0) - 5 + 26 - \"a\".charCodeAt(0)) % 26) + ch.charCodeAt(0)\n )).join(\"\");\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "decodeShift", "signature": "const decodeShift = (s)", "docstring": "takes as input string encoded with encode_shift function. Returns decoded string.", "instruction": "Write a JavaScript function `const decodeShift = (s)` to solve the following problem:\ntakes as input string encoded with encode_shift function. Returns decoded string."} +{"task_id": "JavaScript/51", "prompt": "/*\n removeVowels is a function that takes string and returns string without vowels.\n >>> removeVowels('')\n ''\n >>> removeVowels(\"abcdef\\nghijklm\")\n 'bcdf\\nghjklm'\n >>> removeVowels('abcdef')\n 'bcdf'\n >>> removeVowels('aaaaa')\n ''\n >>> removeVowels('aaBAA')\n 'B'\n >>> removeVowels('zbcd')\n 'zbcd'\n */\nconst removeVowels = (text) => {\n", "canonical_solution": " return text.split(\"\")\n .filter(s => ![\"a\", \"e\", \"i\", \"o\", \"u\"]\n .includes(s.toLowerCase())\n )\n .join(\"\")\n}\n\n", "test": "const testRemoveVowels = () => {\n console.assert(removeVowels('') === '')\n console.assert(removeVowels('abcdef\\nghijklm') === 'bcdf\\nghjklm')\n console.assert(removeVowels('fedcba') === 'fdcb')\n console.assert(removeVowels('eeeee') === '')\n console.assert(removeVowels('acBAA') === 'cB')\n console.assert(removeVowels('EcBOO') === 'cB')\n console.assert(removeVowels('ybcd') === 'ybcd')\n}\n\ntestRemoveVowels()\n", "declaration": "\nconst removeVowels = (text) => {\n", "example_test": "const testRemoveVowels = () => {\n console.assert(removeVowels('') === '')\n console.assert(removeVowels('abcdef\\nghijklm') === 'bcdf\\nghjklm')\n console.assert(removeVowels('abcdef') === 'bcdf')\n console.assert(removeVowels('aaaaa') === '')\n console.assert(removeVowels('aaBAA') === 'B')\n console.assert(removeVowels('zbcd') === 'zbcd')\n}\ntestRemoveVowels()\n", "buggy_solution": " return text.split(\"\")\n .filter(s => ![\"a\", \"e\", \"i\", \"o\", \"u\", \"w\", \"y\"]\n .includes(s.toLowerCase())\n )\n .join(\"\")\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "removeVowels", "signature": "const removeVowels = (text)", "docstring": "removeVowels is a function that takes string and returns string without vowels.\n>>> removeVowels('')\n''\n>>> removeVowels(\"abcdef\\nghijklm\")\n'bcdf\\nghjklm'\n>>> removeVowels('abcdef')\n'bcdf'\n>>> removeVowels('aaaaa')\n''\n>>> removeVowels('aaBAA')\n'B'\n>>> removeVowels('zbcd')\n'zbcd'", "instruction": "Write a JavaScript function `const removeVowels = (text)` to solve the following problem:\nremoveVowels is a function that takes string and returns string without vowels.\n>>> removeVowels('')\n''\n>>> removeVowels(\"abcdef\\nghijklm\")\n'bcdf\\nghjklm'\n>>> removeVowels('abcdef')\n'bcdf'\n>>> removeVowels('aaaaa')\n''\n>>> removeVowels('aaBAA')\n'B'\n>>> removeVowels('zbcd')\n'zbcd'"} +{"task_id": "JavaScript/52", "prompt": "/*Return true if all numbers in the list l are below threshold t.\n >>> belowThreshold([1, 2, 4, 10], 100)\n true\n >>> belowThreshold([1, 20, 4, 10], 5)\n false\n */\nconst belowThreshold = (l, t) => {\n", "canonical_solution": " for (const e of l)\n if (e >= t)\n return false;\n return true;\n}\n\n", "test": "const testBelowThreshold = () => {\n console.assert(belowThreshold([1, 2, 4, 10], 100) === true)\n console.assert(belowThreshold([1, 20, 4, 10], 5) === false)\n console.assert(belowThreshold([1, 20, 4, 10], 21) === true)\n console.assert(belowThreshold([1, 20, 4, 10], 22) === true)\n console.assert(belowThreshold([1, 8, 4, 10], 11) === true)\n console.assert(belowThreshold([1, 8, 4, 10], 10) === false)\n}\n\ntestBelowThreshold()\n", "declaration": "\nconst belowThreshold = (l, t) => {\n", "example_test": "const testBelowThreshold = () => {\n console.assert(belowThreshold([1, 2, 4, 10], 100) === true)\n console.assert(belowThreshold([1, 20, 4, 10], 5) === false)\n}\ntestBelowThreshold()\n", "buggy_solution": " for (const e of l)\n if (e >= t)\n return true;\n return false;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "belowThreshold", "signature": "const belowThreshold = (l, t)", "docstring": "Return true if all numbers in the list l are below threshold t.\n>>> belowThreshold([1, 2, 4, 10], 100)\ntrue\n>>> belowThreshold([1, 20, 4, 10], 5)\nfalse", "instruction": "Write a JavaScript function `const belowThreshold = (l, t)` to solve the following problem:\nReturn true if all numbers in the list l are below threshold t.\n>>> belowThreshold([1, 2, 4, 10], 100)\ntrue\n>>> belowThreshold([1, 20, 4, 10], 5)\nfalse"} +{"task_id": "JavaScript/53", "prompt": "/*Add two numbers x and y\n >>> add(2, 3)\n 5\n >>> add(5, 7)\n 12\n */\nconst add = (x, y) => {\n", "canonical_solution": " return x + y;\n}\n\n", "test": "const testAdd = () => {\n const getRandomIntInclusive = (min = 0, max = 9) => {\n min = Math.ceil(min)\n max = Math.floor(max)\n return Math.floor(Math.random() * (max - min + 1)) + min //\u542b\u6700\u5927\u503c\uff0c\u542b\u6700\u5c0f\u503c\n }\n\n console.assert(add(0, 1) === 1)\n console.assert(add(1, 0) === 1)\n console.assert(add(2, 3) === 5)\n console.assert(add(5, 7) === 12)\n console.assert(add(7, 5) === 12)\n\n for (let i = 0; i < 100; i++) {\n let x = getRandomIntInclusive()\n let y = getRandomIntInclusive()\n console.assert(x + y === add(x, y))\n }\n}\n\ntestAdd()\n", "declaration": "\nconst add = (x, y) => {\n", "example_test": "const testAdd = () => {\n const getRandomIntInclusive = (min = 0, max = 9) => {\n min = Math.ceil(min)\n max = Math.floor(max)\n return Math.floor(Math.random() * (max - min + 1)) + min //\u542b\u6700\u5927\u503c\uff0c\u542b\u6700\u5c0f\u503c\n }\n console.assert(add(2, 3) === 5)\n console.assert(add(5, 7) === 12)\n}\ntestAdd()\n", "buggy_solution": " return x + y + y + x;\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "add", "signature": "const add = (x, y)", "docstring": "Add two numbers x and y\n>>> add(2, 3)\n5\n>>> add(5, 7)\n12", "instruction": "Write a JavaScript function `const add = (x, y)` to solve the following problem:\nAdd two numbers x and y\n>>> add(2, 3)\n5\n>>> add(5, 7)\n12"} +{"task_id": "JavaScript/54", "prompt": "/*\n Check if two words have the same characters.\n >>> sameChars('eabcdzzzz', 'dddzzzzzzzddeddabc')\n true\n >>> sameChars('abcd', 'dddddddabc')\n true\n >>> sameChars('dddddddabc', 'abcd')\n true\n >>> sameChars('eabcd', 'dddddddabc')\n false\n >>> sameChars('abcd', 'dddddddabce')\n false\n >>> sameChars('eabcdzzzz', 'dddzzzzzzzddddabc')\n false\n */\nconst sameChars = (s0, s1) => {\n", "canonical_solution": " return JSON.stringify([...new Set(s0)].sort()) === JSON.stringify([...new Set(s1)].sort());\n}\n\n", "test": "const testSameChars = () => {\n console.assert(sameChars('eabcdzzzz', 'dddzzzzzzzddeddabc') === true)\n console.assert(sameChars('abcd', 'dddddddabc') === true)\n console.assert(sameChars('dddddddabc', 'abcd') === true)\n console.assert(sameChars('eabcd', 'dddddddabc') === false)\n console.assert(sameChars('abcd', 'dddddddabcf') === false)\n console.assert(sameChars('eabcdzzzz', 'dddzzzzzzzddddabc') === false)\n console.assert(sameChars('aabb', 'aaccc') === false)\n}\n\ntestSameChars()\n", "declaration": "\nconst sameChars = (s0, s1) => {\n", "example_test": "const testSameChars = () => {\n console.assert(sameChars('eabcdzzzz', 'dddzzzzzzzddeddabc') === true)\n console.assert(sameChars('abcd', 'dddddddabc') === true)\n console.assert(sameChars('dddddddabc', 'abcd') === true)\n console.assert(sameChars('eabcd', 'dddddddabc') === false)\n console.assert(sameChars('abcd', 'dddddddabcf') === false)\n console.assert(sameChars('eabcdzzzz', 'dddzzzzzzzddddabc') === false)\n}\ntestSameChars()\n", "buggy_solution": " return JSON.stringify([...new Set(s0)]) === JSON.stringify([...new Set(s1)]);\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sameChars", "signature": "const sameChars = (s0, s1)", "docstring": "Check if two words have the same characters.\n>>> sameChars('eabcdzzzz', 'dddzzzzzzzddeddabc')\ntrue\n>>> sameChars('abcd', 'dddddddabc')\ntrue\n>>> sameChars('dddddddabc', 'abcd')\ntrue\n>>> sameChars('eabcd', 'dddddddabc')\nfalse\n>>> sameChars('abcd', 'dddddddabce')\nfalse\n>>> sameChars('eabcdzzzz', 'dddzzzzzzzddddabc')\nfalse", "instruction": "Write a JavaScript function `const sameChars = (s0, s1)` to solve the following problem:\nCheck if two words have the same characters.\n>>> sameChars('eabcdzzzz', 'dddzzzzzzzddeddabc')\ntrue\n>>> sameChars('abcd', 'dddddddabc')\ntrue\n>>> sameChars('dddddddabc', 'abcd')\ntrue\n>>> sameChars('eabcd', 'dddddddabc')\nfalse\n>>> sameChars('abcd', 'dddddddabce')\nfalse\n>>> sameChars('eabcdzzzz', 'dddzzzzzzzddddabc')\nfalse"} +{"task_id": "JavaScript/55", "prompt": "/*Return n-th Fibonacci number.\n >>> fib(10)\n 55\n >>> fib(1)\n 1\n >>> fib(8)\n 21\n */\nconst fib = (n) => {\n", "canonical_solution": " if (n == 0)\n return 0;\n if (n == 1)\n return 1;\n return fib(n - 1) + fib(n - 2);\n}\n\n", "test": "const testFib = () => {\n console.assert(fib(10) === 55)\n console.assert(fib(1) === 1)\n console.assert(fib(8) === 21)\n console.assert(fib(11) === 89)\n console.assert(fib(12) === 144)\n}\n\ntestFib()\n", "declaration": "\nconst fib = (n) => {\n", "example_test": "const testFib = () => {\n console.assert(fib(10) === 55)\n console.assert(fib(1) === 1)\n console.assert(fib(8) === 21)\n}\ntestFib()\n", "buggy_solution": " if (n == 0)\n return 0;\n if (n == 1)\n return 1;\n if (n == 2)\n return 2;\n return fib(n - 1) + fib(n - 2);\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "fib", "signature": "const fib = (n)", "docstring": "Return n-th Fibonacci number.\n>>> fib(10)\n55\n>>> fib(1)\n1\n>>> fib(8)\n21", "instruction": "Write a JavaScript function `const fib = (n)` to solve the following problem:\nReturn n-th Fibonacci number.\n>>> fib(10)\n55\n>>> fib(1)\n1\n>>> fib(8)\n21"} +{"task_id": "JavaScript/56", "prompt": "/* brackets is a string of \"<\" and \">\".\n return false if every opening bracket has a corresponding closing bracket.\n\n >>> correctBracketing(\"<\")\n false\n >>> correctBracketing(\"<>\")\n false\n >>> correctBracketing(\"<<><>>\")\n false\n >>> correctBracketing(\"><<>\")\n false\n */\nconst correctBracketing = (brackets) => {\n", "canonical_solution": " var depth = 0;\n for (const b of brackets) {\n if (b == \"<\")\n depth += 1;\n else\n depth -= 1;\n if (depth < 0)\n return false;\n }\n return depth == 0;\n}\n\n", "test": "const testCorrectBracketing = () => {\n console.assert(correctBracketing('<>') === true)\n console.assert(correctBracketing('<<><>>') === true)\n console.assert(correctBracketing('<><><<><>><>') === true)\n console.assert(correctBracketing('<><><<<><><>><>><<><><<>>>') === true)\n console.assert(correctBracketing('<<<><>>>>') === false)\n console.assert(correctBracketing('><<>') === false)\n console.assert(correctBracketing('<') === false)\n console.assert(correctBracketing('<<<<') === false)\n console.assert(correctBracketing('>') === false)\n console.assert(correctBracketing('<<>') === false)\n console.assert(correctBracketing('<><><<><>><>><<>') === false)\n console.assert(correctBracketing('<><><<><>><>>><>') === false)\n}\n\ntestCorrectBracketing()\n", "declaration": "\nconst correctBracketing = (brackets) => {\n", "example_test": "const testCorrectBracketing = () => {\n console.assert(correctBracketing('<>') === true)\n console.assert(correctBracketing('<<><>>') === true)\n console.assert(correctBracketing('><<>') === false)\n console.assert(correctBracketing('<') === false)\n}\ntestCorrectBracketing()\n", "buggy_solution": " var depth = 0;\n for (const b of brackets) {\n if (b == \">\")\n depth += 1;\n else\n depth -= 1;\n if (depth < 0)\n return false;\n }\n return depth == 0;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "correctBracketing", "signature": "const correctBracketing = (brackets)", "docstring": "brackets is a string of \"<\" and \">\".\nreturn false if every opening bracket has a corresponding closing bracket.\n>>> correctBracketing(\"<\")\nfalse\n>>> correctBracketing(\"<>\")\nfalse\n>>> correctBracketing(\"<<><>>\")\nfalse\n>>> correctBracketing(\"><<>\")\nfalse", "instruction": "Write a JavaScript function `const correctBracketing = (brackets)` to solve the following problem:\nbrackets is a string of \"<\" and \">\".\nreturn false if every opening bracket has a corresponding closing bracket.\n>>> correctBracketing(\"<\")\nfalse\n>>> correctBracketing(\"<>\")\nfalse\n>>> correctBracketing(\"<<><>>\")\nfalse\n>>> correctBracketing(\"><<>\")\nfalse"} +{"task_id": "JavaScript/57", "prompt": "/*Return true is list elements are monotonically increasing or decreasing.\n >>> monotonic([1, 2, 4, 20])\n true\n >>> monotonic([1, 20, 4, 10])\n false\n >>> monotonic([4, 1, 0, -10])\n true\n */\nconst monotonic = (l) => {\n", "canonical_solution": " var sort1 = [...l].sort((a, b) => a - b);\n var sort2 = [...l].sort((a, b) => b - a);\n if (JSON.stringify(l) === JSON.stringify(sort1) ||\n JSON.stringify(l) === JSON.stringify(sort2))\n return true;\n return false;\n}\n\n", "test": "const testMonotonic = () => {\n console.assert(monotonic([1, 2, 4, 10]) === true)\n console.assert(monotonic([1, 2, 4, 20]) === true)\n console.assert(monotonic([1, 20, 4, 10]) === false)\n console.assert(monotonic([4, 1, 0, -10]) === true)\n console.assert(monotonic([4, 1, 1, 0]) === true)\n console.assert(monotonic([1, 2, 3, 2, 5, 60]) === false)\n console.assert(monotonic([1, 2, 3, 4, 5, 60]) === true)\n console.assert(monotonic([9, 9, 9, 9]) === true)\n}\n\ntestMonotonic()\n", "declaration": "\nconst monotonic = (l) => {\n", "example_test": "const testMonotonic = () => {\n console.assert(monotonic([1, 2, 4, 10]) === true)\n console.assert(monotonic([1, 20, 4, 10]) === false)\n console.assert(monotonic([4, 1, 0, -10]) === true)\n}\ntestMonotonic()\n", "buggy_solution": " var sort1 = [...l].sort((a, b) => a - b);\n var sort2 = [...l].sort((a, b) => b - a);\n if (JSON.stringify(l) === JSON.stringify(sort1) ||\n JSON.stringify(l) === JSON.stringify(sort2))\n return false;\n return true;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "monotonic", "signature": "const monotonic = (l)", "docstring": "Return true is list elements are monotonically increasing or decreasing.\n>>> monotonic([1, 2, 4, 20])\ntrue\n>>> monotonic([1, 20, 4, 10])\nfalse\n>>> monotonic([4, 1, 0, -10])\ntrue", "instruction": "Write a JavaScript function `const monotonic = (l)` to solve the following problem:\nReturn true is list elements are monotonically increasing or decreasing.\n>>> monotonic([1, 2, 4, 20])\ntrue\n>>> monotonic([1, 20, 4, 10])\nfalse\n>>> monotonic([4, 1, 0, -10])\ntrue"} +{"task_id": "JavaScript/58", "prompt": "/*Return sorted unique common elements for two lists.\n >>> common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121])\n [1, 5, 653]\n >>> common([5, 3, 2, 8], [3, 2])\n [2, 3]\n\n */\nconst common = (l1, l2) => {\n", "canonical_solution": " var ret = new Set();\n for (const e1 of l1)\n for (const e2 of l2)\n if (e1 == e2)\n ret.add(e1);\n return [...ret].sort();\n}\n\n", "test": "const testCommon = () => {\n console.assert(\n JSON.stringify(common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]))\n === JSON.stringify([1, 5, 653])\n )\n console.assert(\n JSON.stringify(common([5, 3, 2, 8], [3, 2]))\n === JSON.stringify([2, 3])\n )\n console.assert(\n JSON.stringify(common([4, 3, 2, 8], [3, 2, 4])) ===\n JSON.stringify([2, 3, 4])\n )\n console.assert(\n JSON.stringify(common([4, 3, 2, 8], [])) === JSON.stringify([])\n )\n}\n\ntestCommon()\n", "declaration": "\nconst common = (l1, l2) => {\n", "example_test": "const testCommon = () => {\n console.assert(\n JSON.stringify(common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]))\n === JSON.stringify([1, 5, 653])\n )\n console.assert(\n JSON.stringify(common([5, 3, 2, 8], [3, 2]))\n === JSON.stringify([2, 3])\n )\n}\ntestCommon()\n", "buggy_solution": " var ret = new Set();\n for (const e1 of l1)\n for (const e2 of l2)\n ret.add(e1);\n return [...ret].sort();\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "common", "signature": "const common = (l1, l2)", "docstring": "Return sorted unique common elements for two lists.\n>>> common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121])\n[1, 5, 653]\n>>> common([5, 3, 2, 8], [3, 2])\n[2, 3]", "instruction": "Write a JavaScript function `const common = (l1, l2)` to solve the following problem:\nReturn sorted unique common elements for two lists.\n>>> common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121])\n[1, 5, 653]\n>>> common([5, 3, 2, 8], [3, 2])\n[2, 3]"} +{"task_id": "JavaScript/59", "prompt": "/*Return the largest prime factor of n. Assume n > 1 and is not a prime.\n >>> largestPrimeFactor(13195)\n 29\n >>> largestPrimeFactor(2048)\n 2\n */\nconst largestPrimeFactor = (n) => {\n", "canonical_solution": " var isPrime = function (k) {\n if (k < 2)\n return false;\n for (let i = 2; i < k - 1; i++)\n if (k % i == 0)\n return false;\n return true;\n }\n\n var largest = 1;\n for (let j = 2; j < n + 1; j++)\n if (n % j == 0 && isPrime(j))\n largest = Math.max(largest, j);\n return largest;\n}\n\n", "test": "const testLargestPrimeFactor = () => {\n console.assert(largestPrimeFactor(15) === 5)\n console.assert(largestPrimeFactor(27) === 3)\n console.assert(largestPrimeFactor(63) === 7)\n console.assert(largestPrimeFactor(330) === 11)\n console.assert(largestPrimeFactor(13195) === 29)\n}\n\ntestLargestPrimeFactor()\n", "declaration": "\nconst largestPrimeFactor = (n) => {\n", "example_test": "const testLargestPrimeFactor = () => {\n console.assert(largestPrimeFactor(2048) === 2)\n console.assert(largestPrimeFactor(13195) === 29)\n}\ntestLargestPrimeFactor()\n", "buggy_solution": " var isPrime = function (k) {\n if (k < 2)\n return false;\n for (let i = 2; i < k - 1; i++)\n if (k % i == 0)\n return false;\n return true;\n }\n\n var largest = 1;\n for (let j = 2; j < n + 1; j++)\n if (n % j == 0 && isPrime(n))\n largest = Math.max(largest, j);\n return largest;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "largestPrimeFactor", "signature": "const largestPrimeFactor = (n)", "docstring": "Return the largest prime factor of n. Assume n > 1 and is not a prime.\n>>> largestPrimeFactor(13195)\n29\n>>> largestPrimeFactor(2048)\n2", "instruction": "Write a JavaScript function `const largestPrimeFactor = (n)` to solve the following problem:\nReturn the largest prime factor of n. Assume n > 1 and is not a prime.\n>>> largestPrimeFactor(13195)\n29\n>>> largestPrimeFactor(2048)\n2"} +{"task_id": "JavaScript/60", "prompt": "/*sumToN is a function that sums numbers from 1 to n.\n >>> sumToN(30)\n 465\n >>> sumToN(100)\n 5050\n >>> sumToN(5)\n 15\n >>> sumToN(10)\n 55\n >>> sumToN(1)\n 1\n */\nconst sumToN = (n) => {\n", "canonical_solution": " return n * (n + 1) / 2;\n}\n\n", "test": "const testSumToN = () => {\n console.assert(sumToN(1) === 1)\n console.assert(sumToN(6) === 21)\n console.assert(sumToN(11) === 66)\n console.assert(sumToN(30) === 465)\n console.assert(sumToN(100) === 5050)\n}\n\ntestSumToN()\n", "declaration": "\nconst sumToN = (n) => {\n", "example_test": "const testSumToN = () => {\n console.assert(sumToN(1) === 1)\n console.assert(sumToN(5) === 15)\n console.assert(sumToN(10) === 55)\n console.assert(sumToN(30) === 465)\n console.assert(sumToN(100) === 5050)\n}\ntestSumToN()\n", "buggy_solution": " return n * n / 2;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "sumToN", "signature": "const sumToN = (n)", "docstring": "sumToN is a function that sums numbers from 1 to n.\n>>> sumToN(30)\n465\n>>> sumToN(100)\n5050\n>>> sumToN(5)\n15\n>>> sumToN(10)\n55\n>>> sumToN(1)\n1", "instruction": "Write a JavaScript function `const sumToN = (n)` to solve the following problem:\nsumToN is a function that sums numbers from 1 to n.\n>>> sumToN(30)\n465\n>>> sumToN(100)\n5050\n>>> sumToN(5)\n15\n>>> sumToN(10)\n55\n>>> sumToN(1)\n1"} +{"task_id": "JavaScript/61", "prompt": "/* brackets is a string of \"(\" and \")\".\n return true if every opening bracket has a corresponding closing bracket.\n\n >>> correctBracketing(\"(\")\n false\n >>> correctBracketing(\"()\")\n true\n >>> correctBracketing(\"(()())\")\n true\n >>> correctBracketing(\")(()\")\n false\n */\nconst correctBracketing = (brackets) => {\n", "canonical_solution": " var depth = 0;\n for (const b of brackets) {\n if (b == \"(\")\n depth += 1;\n else\n depth -= 1;\n if (depth < 0)\n return false;\n }\n return depth == 0;\n}\n\n", "test": "const testCorrectBracketing = () => {\n console.assert(correctBracketing('()') === true)\n console.assert(correctBracketing('(()())') === true)\n console.assert(correctBracketing('()()(()())()') === true)\n console.assert(correctBracketing('()()((()()())())(()()(()))') === true)\n console.assert(correctBracketing('((()())))') === false)\n console.assert(correctBracketing(')(()') === false)\n console.assert(correctBracketing('(') === false)\n console.assert(correctBracketing('((((') === false)\n console.assert(correctBracketing(')') === false)\n console.assert(correctBracketing('(()') === false)\n console.assert(correctBracketing('()()(()())())(()') === false)\n console.assert(correctBracketing('()()(()())()))()') === false)\n}\n\ntestCorrectBracketing()\n", "declaration": "\nconst correctBracketing = (brackets) => {\n", "example_test": "const testCorrectBracketing = () => {\n console.assert(correctBracketing('()') === true)\n console.assert(correctBracketing('(()())') === true)\n console.assert(correctBracketing(')(()') === false)\n console.assert(correctBracketing('(') === false)\n}\ntestCorrectBracketing()\n", "buggy_solution": " var depth = 0;\n for (const b of brackets) {\n if (b == \"(\")\n depth += 1;\n else\n depth -= 1;\n if (depth < 0)\n return true;\n }\n return depth == 0;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "correctBracketing", "signature": "const correctBracketing = (brackets)", "docstring": "brackets is a string of \"(\" and \")\".\nreturn true if every opening bracket has a corresponding closing bracket.\n>>> correctBracketing(\"(\")\nfalse\n>>> correctBracketing(\"()\")\ntrue\n>>> correctBracketing(\"(()())\")\ntrue\n>>> correctBracketing(\")(()\")\nfalse", "instruction": "Write a JavaScript function `const correctBracketing = (brackets)` to solve the following problem:\nbrackets is a string of \"(\" and \")\".\nreturn true if every opening bracket has a corresponding closing bracket.\n>>> correctBracketing(\"(\")\nfalse\n>>> correctBracketing(\"()\")\ntrue\n>>> correctBracketing(\"(()())\")\ntrue\n>>> correctBracketing(\")(()\")\nfalse"} +{"task_id": "JavaScript/62", "prompt": "/* xs represent coefficients of a polynomial.\n xs[0] + xs[1] * x + xs[2] * x^2 + ....\n Return derivative of this polynomial in the same form.\n >>> derivative([3, 1, 2, 4, 5])\n [1, 4, 12, 20]\n >>> derivative([1, 2, 3])\n [2, 6]\n */\nconst derivative = (xs) => {\n", "canonical_solution": " return xs.map((x, i) => x * i).slice(1);\n}\n\n", "test": "const testDerivative = () => {\n console.assert(\n JSON.stringify(derivative([3, 1, 2, 4, 5])) ===\n JSON.stringify([1, 4, 12, 20])\n )\n console.assert(\n JSON.stringify(derivative([1, 2, 3])) === JSON.stringify([2, 6])\n )\n console.assert(\n JSON.stringify(derivative([3, 2, 1])) === JSON.stringify([2, 2])\n )\n console.assert(\n JSON.stringify(derivative([3, 2, 1, 0, 4])) ===\n JSON.stringify([2, 2, 0, 16])\n )\n console.assert(JSON.stringify(derivative([1])) === JSON.stringify([]))\n}\n\ntestDerivative()\n", "declaration": "\nconst derivative = (xs) => {\n", "example_test": "const testDerivative = () => {\n console.assert(\n JSON.stringify(derivative([3, 1, 2, 4, 5])) ===\n JSON.stringify([1, 4, 12, 20])\n )\n console.assert(\n JSON.stringify(derivative([1, 2, 3])) === JSON.stringify([2, 6])\n )\n}\ntestDerivative()\n", "buggy_solution": " return xs.map((x, i) => x * i);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "derivative", "signature": "const derivative = (xs)", "docstring": "xs represent coefficients of a polynomial.\nxs[0] + xs[1] * x + xs[2] * x^2 + ....\nReturn derivative of this polynomial in the same form.\n>>> derivative([3, 1, 2, 4, 5])\n[1, 4, 12, 20]\n>>> derivative([1, 2, 3])\n[2, 6]", "instruction": "Write a JavaScript function `const derivative = (xs)` to solve the following problem:\nxs represent coefficients of a polynomial.\nxs[0] + xs[1] * x + xs[2] * x^2 + ....\nReturn derivative of this polynomial in the same form.\n>>> derivative([3, 1, 2, 4, 5])\n[1, 4, 12, 20]\n>>> derivative([1, 2, 3])\n[2, 6]"} +{"task_id": "JavaScript/63", "prompt": "/*The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\n fibfib(0) == 0\n fibfib(1) == 0\n fibfib(2) == 1\n fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).\n Please write a function to efficiently compute the n-th element of the fibfib number sequence.\n >>> fibfib(1)\n 0\n >>> fibfib(5)\n 4\n >>> fibfib(8)\n 24\n */\nconst fibfib = (n) => {\n", "canonical_solution": " if (n == 0 || n == 1)\n return 0;\n if (n == 2)\n return 1;\n return fibfib(n - 1) + fibfib(n - 2) + fibfib(n - 3);\n}\n\n", "test": "const testFibfib = () => {\n console.assert(fibfib(2) === 1)\n console.assert(fibfib(1) === 0)\n console.assert(fibfib(5) === 4)\n console.assert(fibfib(8) === 24)\n console.assert(fibfib(10) === 81)\n console.assert(fibfib(12) === 274)\n console.assert(fibfib(14) === 927)\n}\n\ntestFibfib()\n", "declaration": "\nconst fibfib = (n) => {\n", "example_test": "const testFibfib = () => {\n console.assert(fibfib(1) === 0)\n console.assert(fibfib(5) === 4)\n console.assert(fibfib(8) === 24)\n}\ntestFibfib()\n", "buggy_solution": " if (n == 0 || n == 1)\n return n;\n if (n == 2)\n return 2;\n return fibfib(n - 1) + fibfib(n - 2) + fibfib(n - 3);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "fibfib", "signature": "const fibfib = (n)", "docstring": "The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\nfibfib(0) == 0\nfibfib(1) == 0\nfibfib(2) == 1\nfibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).\nPlease write a function to efficiently compute the n-th element of the fibfib number sequence.\n>>> fibfib(1)\n0\n>>> fibfib(5)\n4\n>>> fibfib(8)\n24", "instruction": "Write a JavaScript function `const fibfib = (n)` to solve the following problem:\nThe FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\nfibfib(0) == 0\nfibfib(1) == 0\nfibfib(2) == 1\nfibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).\nPlease write a function to efficiently compute the n-th element of the fibfib number sequence.\n>>> fibfib(1)\n0\n>>> fibfib(5)\n4\n>>> fibfib(8)\n24"} +{"task_id": "JavaScript/64", "prompt": "/*Write a function vowelsCount which takes a string representing\n a word as input and returns the number of vowels in the string.\n Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a\n vowel, but only when it is at the end of the given word.\n\n Example:\n >>> vowelsCount(\"abcde\")\n 2\n >>> vowelsCount(\"ACEDY\")\n 3\n */\nconst vowelsCount = (s) => {\n", "canonical_solution": " var vowels = \"aeiouAEIOU\";\n var n_vowels = s.split('').reduce((prev, item) => {\n return prev + (vowels.includes(item));\n }, 0);\n if (s.at(-1) == 'y' || s.at(-1) == 'Y')\n n_vowels += 1;\n return n_vowels;\n}\n\n", "test": "const testVowelsCount = () => {\n console.assert(vowelsCount('abcde') === 2)\n console.assert(vowelsCount('Alone') === 3)\n console.assert(vowelsCount('key') === 2)\n console.assert(vowelsCount('bye') === 1)\n console.assert(vowelsCount('keY') === 2)\n console.assert(vowelsCount('bYe') === 1)\n console.assert(vowelsCount('ACEDY') === 3)\n}\n\ntestVowelsCount()\n", "declaration": "\nconst vowelsCount = (s) => {\n", "example_test": "const testVowelsCount = () => {\n console.assert(vowelsCount('abcde') === 2)\n console.assert(vowelsCount('ACEDY') === 3)\n}\ntestVowelsCount()\n", "buggy_solution": " var vowels = \"aeiouyAEIOUY\";\n var n_vowels = s.split('').reduce((prev, item) => {\n return prev + (vowels.includes(item));\n }, 0);\n return n_vowels;\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "vowelsCount", "signature": "const vowelsCount = (s)", "docstring": "Write a function vowelsCount which takes a string representing\na word as input and returns the number of vowels in the string.\nVowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a\nvowel, but only when it is at the end of the given word.\nExample:\n>>> vowelsCount(\"abcde\")\n2\n>>> vowelsCount(\"ACEDY\")\n3", "instruction": "Write a JavaScript function `const vowelsCount = (s)` to solve the following problem:\nWrite a function vowelsCount which takes a string representing\na word as input and returns the number of vowels in the string.\nVowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a\nvowel, but only when it is at the end of the given word.\nExample:\n>>> vowelsCount(\"abcde\")\n2\n>>> vowelsCount(\"ACEDY\")\n3"} +{"task_id": "JavaScript/65", "prompt": "/*Circular shift the digits of the integer x, shift the digits right by shift\n and return the result as a string.\n If shift > number of digits, return digits reversed.\n >>> circularShift(12, 1)\n \"21\"\n >>> circularShift(12, 2)\n \"12\"\n */\nconst circularShift = (x, shift) => {\n", "canonical_solution": " s = x.toString();\n if (shift > s.length)\n return s.split('').reverse().join('');\n else\n return s.slice(-shift) + s.slice(0, -shift);\n}\n\n", "test": "const testCircularShift = () => {\n console.assert(circularShift(100, 2) === '001')\n console.assert(circularShift(12, 2) === '12')\n console.assert(circularShift(97, 8) === '79')\n console.assert(circularShift(12, 1) === '21')\n console.assert(circularShift(11, 101) === '11')\n}\n\ntestCircularShift()\n", "declaration": "\nconst circularShift = (x, shift) => {\n", "example_test": "const testCircularShift = () => {\n console.assert(circularShift(12, 2) === '12')\n console.assert(circularShift(12, 1) === '21')\n}\ntestCircularShift()\n", "buggy_solution": " s = x.toString();\n if (shift > s.length)\n return s.split('').reverse().join('');\n else\n return s.slice(0, -shift) + s.slice(-shift);\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "circularShift", "signature": "const circularShift = (x, shift)", "docstring": "Circular shift the digits of the integer x, shift the digits right by shift\nand return the result as a string.\nIf shift > number of digits, return digits reversed.\n>>> circularShift(12, 1)\n\"21\"\n>>> circularShift(12, 2)\n\"12\"", "instruction": "Write a JavaScript function `const circularShift = (x, shift)` to solve the following problem:\nCircular shift the digits of the integer x, shift the digits right by shift\nand return the result as a string.\nIf shift > number of digits, return digits reversed.\n>>> circularShift(12, 1)\n\"21\"\n>>> circularShift(12, 2)\n\"12\""} +{"task_id": "JavaScript/66", "prompt": "/*Task\n Write a function that takes a string as input and returns the sum of the upper characters only'\n ASCII codes.\n\n Examples:\n digitSum(\"\") => 0\n digitSum(\"abAB\") => 131\n digitSum(\"abcCd\") => 67\n digitSum(\"helloE\") => 69\n digitSum(\"woArBld\") => 131\n digitSum(\"aAaaaXa\") => 153\n */\nconst digitSum = (s) => {\n", "canonical_solution": " if (s == '') return 0;\n return s.split('').reduce((prev, char) => {\n let ord_char = char.charCodeAt(0)\n return prev + (ord_char > 64 && ord_char < 91 ? ord_char : 0);\n }, 0);\n}\n\n", "test": "const testDigitSum = () => {\n console.assert(digitSum('') === 0)\n console.assert(digitSum('abAB') === 131)\n console.assert(digitSum('abcCd') === 67)\n console.assert(digitSum('helloE') === 69)\n console.assert(digitSum('woArBld') === 131)\n console.assert(digitSum('aAaaaXa') === 153)\n console.assert(digitSum(' How are yOu?') === 151)\n console.assert(digitSum('You arE Very Smart') === 327)\n}\n\ntestDigitSum()\n", "declaration": "\nconst digitSum = (s) => {\n", "example_test": "const testDigitSum = () => {\n console.assert(digitSum('') === 0)\n console.assert(digitSum('abAB') === 131)\n console.assert(digitSum('abcCd') === 67)\n console.assert(digitSum('helloE') === 69)\n console.assert(digitSum('woArBld') === 131)\n console.assert(digitSum('aAaaaXa') === 153)\n}\ntestDigitSum()\n", "buggy_solution": " if (s == '') return 0;\n return s.split('').reduce((prev, char) => {\n let ord_char = char.charCodeAt(0)\n return prev + (ord_char > 64 && ord_char < 100 ? ord_char : 0);\n }, 0);\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "digitSum", "signature": "const digitSum = (s)", "docstring": "Task\nWrite a function that takes a string as input and returns the sum of the upper characters only'\nASCII codes.\nExamples:\ndigitSum(\"\") => 0\ndigitSum(\"abAB\") => 131\ndigitSum(\"abcCd\") => 67\ndigitSum(\"helloE\") => 69\ndigitSum(\"woArBld\") => 131\ndigitSum(\"aAaaaXa\") => 153", "instruction": "Write a JavaScript function `const digitSum = (s)` to solve the following problem:\nTask\nWrite a function that takes a string as input and returns the sum of the upper characters only'\nASCII codes.\nExamples:\ndigitSum(\"\") => 0\ndigitSum(\"abAB\") => 131\ndigitSum(\"abcCd\") => 67\ndigitSum(\"helloE\") => 69\ndigitSum(\"woArBld\") => 131\ndigitSum(\"aAaaaXa\") => 153"} +{"task_id": "JavaScript/67", "prompt": "/*\n In this task, you will be given a string that represents a number of apples and oranges\n that are distributed in a basket of fruit this basket contains\n apples, oranges, and mango fruits. Given the string that represents the total number of\n the oranges and apples and an integer that represent the total number of the fruits\n in the basket return the number of the mango fruits in the basket.\n for examble:\n fruitDistribution(\"5 apples and 6 oranges\", 19) ->19 - 5 - 6 = 8\n fruitDistribution(\"0 apples and 1 oranges\",3) -> 3 - 0 - 1 = 2\n fruitDistribution(\"2 apples and 3 oranges\", 100) -> 100 - 2 - 3 = 95\n fruitDistribution(\"100 apples and 1 oranges\",120) -> 120 - 100 - 1 = 19\n */\nconst fruitDistribution = (s, n) => {\n", "canonical_solution": " var lis = [];\n for (const i of s.split(\" \"))\n if (!isNaN(i))\n lis.push(Number(i))\n return n - lis.reduce(((prev, item) => prev + item), 0);\n}\n\n", "test": "const testFruitDistribution = () => {\n console.assert(fruitDistribution('5 apples and 6 oranges', 19) === 8)\n console.assert(fruitDistribution('5 apples and 6 oranges', 21) === 10)\n console.assert(fruitDistribution('0 apples and 1 oranges', 3) === 2)\n console.assert(fruitDistribution('1 apples and 0 oranges', 3) === 2)\n console.assert(fruitDistribution('2 apples and 3 oranges', 100) === 95)\n console.assert(fruitDistribution('2 apples and 3 oranges', 5) === 0)\n console.assert(fruitDistribution('1 apples and 100 oranges', 120) === 19)\n}\n\ntestFruitDistribution()\n", "declaration": "\nconst fruitDistribution = (s, n) => {\n", "example_test": "const testFruitDistribution = () => {\n console.assert(fruitDistribution('5 apples and 6 oranges', 19) === 8)\n console.assert(fruitDistribution('0 apples and 1 oranges', 3) === 2)\n console.assert(fruitDistribution('2 apples and 3 oranges', 100) === 95)\n console.assert(fruitDistribution('1 apples and 100 oranges', 120) === 19)\n}\ntestFruitDistribution()\n", "buggy_solution": " var lis = [];\n for (const i of s.split(\" \"))\n if (!isNaN(i))\n lis.push(Number(i))\n return n - 1 - lis.reduce(((prev, item) => prev + item), 0);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "fruitDistribution", "signature": "const fruitDistribution = (s, n)", "docstring": "In this task, you will be given a string that represents a number of apples and oranges\nthat are distributed in a basket of fruit this basket contains\napples, oranges, and mango fruits. Given the string that represents the total number of\nthe oranges and apples and an integer that represent the total number of the fruits\nin the basket return the number of the mango fruits in the basket.\nfor examble:\nfruitDistribution(\"5 apples and 6 oranges\", 19) ->19 - 5 - 6 = 8\nfruitDistribution(\"0 apples and 1 oranges\",3) -> 3 - 0 - 1 = 2\nfruitDistribution(\"2 apples and 3 oranges\", 100) -> 100 - 2 - 3 = 95\nfruitDistribution(\"100 apples and 1 oranges\",120) -> 120 - 100 - 1 = 19", "instruction": "Write a JavaScript function `const fruitDistribution = (s, n)` to solve the following problem:\nIn this task, you will be given a string that represents a number of apples and oranges\nthat are distributed in a basket of fruit this basket contains\napples, oranges, and mango fruits. Given the string that represents the total number of\nthe oranges and apples and an integer that represent the total number of the fruits\nin the basket return the number of the mango fruits in the basket.\nfor examble:\nfruitDistribution(\"5 apples and 6 oranges\", 19) ->19 - 5 - 6 = 8\nfruitDistribution(\"0 apples and 1 oranges\",3) -> 3 - 0 - 1 = 2\nfruitDistribution(\"2 apples and 3 oranges\", 100) -> 100 - 2 - 3 = 95\nfruitDistribution(\"100 apples and 1 oranges\",120) -> 120 - 100 - 1 = 19"} +{"task_id": "JavaScript/68", "prompt": "/*\n \"Given an array representing a branch of a tree that has non-negative integer nodes\n your task is to pluck one of the nodes and return it.\n The plucked node should be the node with the smallest even value.\n If multiple nodes with the same smallest even value are found return the node that has smallest index.\n\n The plucked node should be returned in a list, [ smalest_value, its index ],\n If there are no even values or the given array is empty, return [].\n\n Example 1:\n Input: [4,2,3]\n Output: [2, 1]\n Explanation: 2 has the smallest even value, and 2 has the smallest index.\n\n Example 2:\n Input: [1,2,3]\n Output: [2, 1]\n Explanation: 2 has the smallest even value, and 2 has the smallest index.\n\n Example 3:\n Input: []\n Output: []\n\n Example 4:\n Input: [5, 0, 3, 0, 4, 2]\n Output: [0, 1]\n Explanation: 0 is the smallest value, but there are two zeros,\n so we will choose the first zero, which has the smallest index.\n\n Constraints:\n * 1 <= nodes.length <= 10000\n * 0 <= node.value\n */\nconst pluck = (arr) => {\n", "canonical_solution": " if (arr.length == 0) return [];\n var evens = arr.filter(x => x % 2 == 0);\n if (evens.length == 0) return [];\n return [Math.min(...evens), arr.indexOf(Math.min(...evens))];\n}\n\n", "test": "const testPluck = () => {\n console.assert(JSON.stringify(pluck([4, 2, 3])) === JSON.stringify([2, 1]))\n console.assert(JSON.stringify(pluck([1, 2, 3])) === JSON.stringify([2, 1]))\n console.assert(JSON.stringify(pluck([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(pluck([5, 0, 3, 0, 4, 2])) === JSON.stringify([0, 1])\n )\n console.assert(\n JSON.stringify(pluck([1, 2, 3, 0, 5, 3])) === JSON.stringify([0, 3])\n )\n console.assert(\n JSON.stringify(pluck([5, 4, 8, 4, 8])) === JSON.stringify([4, 1])\n )\n console.assert(JSON.stringify(pluck([7, 6, 7, 1])) === JSON.stringify([6, 1]))\n console.assert(JSON.stringify(pluck([7, 9, 7, 1])) === JSON.stringify([]))\n}\n\ntestPluck()\n", "declaration": "\nconst pluck = (arr) => {\n", "example_test": "const testPluck = () => {\n console.assert(JSON.stringify(pluck([4, 2, 3])) === JSON.stringify([2, 1]))\n console.assert(JSON.stringify(pluck([1, 2, 3])) === JSON.stringify([2, 1]))\n console.assert(JSON.stringify(pluck([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(pluck([5, 0, 3, 0, 4, 2])) === JSON.stringify([0, 1])\n )\n}\ntestPluck()\n", "buggy_solution": " if (arr.length == 0) return [];\n var evens = arr.filter(x => x % 2 == 0);\n if (evens.length == 0) return [];\n return [arr.indexOf(Math.min(...evens)), Math.min(...evens)];\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "pluck", "signature": "const pluck = (arr)", "docstring": "\"Given an array representing a branch of a tree that has non-negative integer nodes\nyour task is to pluck one of the nodes and return it.\nThe plucked node should be the node with the smallest even value.\nIf multiple nodes with the same smallest even value are found return the node that has smallest index.\nThe plucked node should be returned in a list, [ smalest_value, its index ],\nIf there are no even values or the given array is empty, return [].\nExample 1:\nInput: [4,2,3]\nOutput: [2, 1]\nExplanation: 2 has the smallest even value, and 2 has the smallest index.\nExample 2:\nInput: [1,2,3]\nOutput: [2, 1]\nExplanation: 2 has the smallest even value, and 2 has the smallest index.\nExample 3:\nInput: []\nOutput: []\nExample 4:\nInput: [5, 0, 3, 0, 4, 2]\nOutput: [0, 1]\nExplanation: 0 is the smallest value, but there are two zeros,\nso we will choose the first zero, which has the smallest index.\nConstraints:\n* 1 <= nodes.length <= 10000\n* 0 <= node.value", "instruction": "Write a JavaScript function `const pluck = (arr)` to solve the following problem:\n\"Given an array representing a branch of a tree that has non-negative integer nodes\nyour task is to pluck one of the nodes and return it.\nThe plucked node should be the node with the smallest even value.\nIf multiple nodes with the same smallest even value are found return the node that has smallest index.\nThe plucked node should be returned in a list, [ smalest_value, its index ],\nIf there are no even values or the given array is empty, return [].\nExample 1:\nInput: [4,2,3]\nOutput: [2, 1]\nExplanation: 2 has the smallest even value, and 2 has the smallest index.\nExample 2:\nInput: [1,2,3]\nOutput: [2, 1]\nExplanation: 2 has the smallest even value, and 2 has the smallest index.\nExample 3:\nInput: []\nOutput: []\nExample 4:\nInput: [5, 0, 3, 0, 4, 2]\nOutput: [0, 1]\nExplanation: 0 is the smallest value, but there are two zeros,\nso we will choose the first zero, which has the smallest index.\nConstraints:\n* 1 <= nodes.length <= 10000\n* 0 <= node.value"} +{"task_id": "JavaScript/69", "prompt": "/*\n You are given a non-empty list of positive integers. Return the greatest integer that is greater than\n zero, and has a frequency greater than or equal to the value of the integer itself.\n The frequency of an integer is the number of times it appears in the list.\n If no such a value exist, return -1.\n Examples:\n search([4, 1, 2, 2, 3, 1])) == 2\n search([1, 2, 2, 3, 3, 3, 4, 4, 4])) == 3\n search([5, 5, 4, 4, 4])) == -1\n */\nconst search = (lst) => {\n", "canonical_solution": " var frq = new Array(Math.max(...lst) + 1).fill(0);\n for (const i of lst)\n frq[i] += 1;\n var ans = -1;\n for (let i = 1; i < frq.length; i++)\n if (frq[i] >= i)\n ans = i;\n return ans;\n}\n\n", "test": "const testSearch = () => {\n console.assert(search([5, 5, 5, 5, 1]) === 1)\n console.assert(search([4, 1, 4, 1, 4, 4]) === 4)\n console.assert(search([3, 3]) === -1)\n console.assert(search([8, 8, 8, 8, 8, 8, 8, 8]) === 8)\n console.assert(search([2, 3, 3, 2, 2]) === 2)\n console.assert(\n search([\n 2, 7, 8, 8, 4, 8, 7, 3, 9, 6, 5, 10, 4, 3, 6, 7, 1, 7, 4, 10, 8, 1,\n ]) === 1\n )\n console.assert(search([3, 2, 8, 2]) === 2)\n console.assert(search([6, 7, 1, 8, 8, 10, 5, 8, 5, 3, 10]) === 1)\n console.assert(search([8, 8, 3, 6, 5, 6, 4]) === -1)\n console.assert(\n search([\n 6, 9, 6, 7, 1, 4, 7, 1, 8, 8, 9, 8, 10, 10, 8, 4, 10, 4, 10, 1, 2, 9, 5,\n 7, 9,\n ]) === 1\n )\n console.assert(search([1, 9, 10, 1, 3]) === 1)\n console.assert(\n search([\n 6, 9, 7, 5, 8, 7, 5, 3, 7, 5, 10, 10, 3, 6, 10, 2, 8, 6, 5, 4, 9, 5, 3,\n 10,\n ]) === 5\n )\n console.assert(search([1]) === 1)\n console.assert(\n search([\n 8, 8, 10, 6, 4, 3, 5, 8, 2, 4, 2, 8, 4, 6, 10, 4, 2, 1, 10, 2, 1, 1, 5,\n ]) === 4\n )\n console.assert(\n search([2, 10, 4, 8, 2, 10, 5, 1, 2, 9, 5, 5, 6, 3, 8, 6, 4, 10]) === 2\n )\n console.assert(search([1, 6, 10, 1, 6, 9, 10, 8, 6, 8, 7, 3]) === 1)\n console.assert(\n search([\n 9, 2, 4, 1, 5, 1, 5, 2, 5, 7, 7, 7, 3, 10, 1, 5, 4, 2, 8, 4, 1, 9, 10, 7,\n 10, 2, 8, 10, 9, 4,\n ]) === 4\n )\n console.assert(\n search([\n 2, 6, 4, 2, 8, 7, 5, 6, 4, 10, 4, 6, 3, 7, 8, 8, 3, 1, 4, 2, 2, 10, 7,\n ]) === 4\n )\n console.assert(\n search([9, 8, 6, 10, 2, 6, 10, 2, 7, 8, 10, 3, 8, 2, 6, 2, 3, 1]) === 2\n )\n console.assert(\n search([\n 5, 5, 3, 9, 5, 6, 3, 2, 8, 5, 6, 10, 10, 6, 8, 4, 10, 7, 7, 10, 8,\n ]) === -1\n )\n console.assert(search([10]) === -1)\n console.assert(search([9, 7, 7, 2, 4, 7, 2, 10, 9, 7, 5, 7, 2]) === 2)\n console.assert(search([5, 4, 10, 2, 1, 1, 10, 3, 6, 1, 8]) === 1)\n console.assert(\n search([\n 7, 9, 9, 9, 3, 4, 1, 5, 9, 1, 2, 1, 1, 10, 7, 5, 6, 7, 6, 7, 7, 6,\n ]) === 1\n )\n console.assert(search([3, 10, 10, 9, 2]) === -1)\n}\n\ntestSearch()\n", "declaration": "\nconst search = (lst) => {\n", "example_test": "const testSearch = () => {\n console.assert(search([4, 1, 2, 2, 3, 1]) === 2)\n console.assert(search([1, 2, 2, 3, 3, 3, 4, 4, 4]) === 3)\n console.assert(search([5, 5, 4, 4, 4]) === -1)\n}\ntestSearch()\n", "buggy_solution": " var frq = new Array(Math.max(...lst) + 1).fill(0);\n for (const i of lst)\n frq[i] += 1;\n var ans = 0;\n for (let i = 1; i < frq.length; i++)\n if (frq[i] >= i)\n ans = i;\n return ans;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "search", "signature": "const search = (lst)", "docstring": "You are given a non-empty list of positive integers. Return the greatest integer that is greater than\nzero, and has a frequency greater than or equal to the value of the integer itself.\nThe frequency of an integer is the number of times it appears in the list.\nIf no such a value exist, return -1.\nExamples:\nsearch([4, 1, 2, 2, 3, 1])) == 2\nsearch([1, 2, 2, 3, 3, 3, 4, 4, 4])) == 3\nsearch([5, 5, 4, 4, 4])) == -1", "instruction": "Write a JavaScript function `const search = (lst)` to solve the following problem:\nYou are given a non-empty list of positive integers. Return the greatest integer that is greater than\nzero, and has a frequency greater than or equal to the value of the integer itself.\nThe frequency of an integer is the number of times it appears in the list.\nIf no such a value exist, return -1.\nExamples:\nsearch([4, 1, 2, 2, 3, 1])) == 2\nsearch([1, 2, 2, 3, 3, 3, 4, 4, 4])) == 3\nsearch([5, 5, 4, 4, 4])) == -1"} +{"task_id": "JavaScript/70", "prompt": "/*\n Given list of integers, return list in strange order.\n Strange sorting, is when you start with the minimum value,\n then maximum of the remaining integers, then minimum and so on.\n\n Examples:\n strangeSortList([1, 2, 3, 4]) == [1, 4, 2, 3]\n strangeSortList([5, 5, 5, 5]) == [5, 5, 5, 5]\n strangeSortList([]) == []\n */\nconst strangeSortList = (lst) => {\n", "canonical_solution": " var res = [], sw = true;\n while (lst.length) {\n res.push(sw ? Math.min(...lst) : Math.max(...lst));\n lst.splice(lst.indexOf(res.at(-1)), 1);\n sw = !sw;\n }\n return res;\n}\n\n", "test": "const testStrangeSortList = () => {\n console.assert(\n JSON.stringify(strangeSortList([1, 2, 3, 4])) ===\n JSON.stringify([1, 4, 2, 3])\n )\n console.assert(\n JSON.stringify(strangeSortList([5, 6, 7, 8, 9])) ===\n JSON.stringify([5, 9, 6, 8, 7])\n )\n console.assert(\n JSON.stringify(strangeSortList([1, 2, 3, 4, 5])) ===\n JSON.stringify([1, 5, 2, 4, 3])\n )\n console.assert(\n JSON.stringify(strangeSortList([5, 6, 7, 8, 9, 1])) ===\n JSON.stringify([1, 9, 5, 8, 6, 7])\n )\n console.assert(\n JSON.stringify(strangeSortList([5, 5, 5, 5])) ===\n JSON.stringify([5, 5, 5, 5])\n )\n console.assert(JSON.stringify(strangeSortList([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(strangeSortList([1, 2, 3, 4, 5, 6, 7, 8])) ===\n JSON.stringify([1, 8, 2, 7, 3, 6, 4, 5])\n )\n console.assert(\n JSON.stringify(strangeSortList([0, 2, 2, 2, 5, 5, -5, -5])) ===\n JSON.stringify([-5, 5, -5, 5, 0, 2, 2, 2])\n )\n console.assert(\n JSON.stringify(strangeSortList([111111])) === JSON.stringify([111111])\n )\n}\n\ntestStrangeSortList()\n", "declaration": "\nconst strangeSortList = (lst) => {\n", "example_test": "const testStrangeSortList = () => {\n console.assert(\n JSON.stringify(strangeSortList([1, 2, 3, 4])) ===\n JSON.stringify([1, 4, 2, 3])\n )\n console.assert(\n JSON.stringify(strangeSortList([5, 5, 5, 5])) ===\n JSON.stringify([5, 5, 5, 5])\n )\n console.assert(JSON.stringify(strangeSortList([])) === JSON.stringify([]))\n}\ntestStrangeSortList()\n", "buggy_solution": " var res = [], sw = false;\n while (lst.length) {\n res.push(sw ? Math.min(...lst) : Math.max(...lst));\n lst.splice(lst.indexOf(res.at(-1)), 1);\n sw = !sw;\n }\n return res;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "strangeSortList", "signature": "const strangeSortList = (lst)", "docstring": "Given list of integers, return list in strange order.\nStrange sorting, is when you start with the minimum value,\nthen maximum of the remaining integers, then minimum and so on.\nExamples:\nstrangeSortList([1, 2, 3, 4]) == [1, 4, 2, 3]\nstrangeSortList([5, 5, 5, 5]) == [5, 5, 5, 5]\nstrangeSortList([]) == []", "instruction": "Write a JavaScript function `const strangeSortList = (lst)` to solve the following problem:\nGiven list of integers, return list in strange order.\nStrange sorting, is when you start with the minimum value,\nthen maximum of the remaining integers, then minimum and so on.\nExamples:\nstrangeSortList([1, 2, 3, 4]) == [1, 4, 2, 3]\nstrangeSortList([5, 5, 5, 5]) == [5, 5, 5, 5]\nstrangeSortList([]) == []"} +{"task_id": "JavaScript/71", "prompt": "/*\n Given the lengths of the three sides of a triangle. Return the area of\n the triangle rounded to 2 decimal points if the three sides form a valid triangle.\n Otherwise return -1\n Three sides make a valid triangle when the sum of any two sides is greater\n than the third side.\n Example:\n triangleArea(3, 4, 5) == 6.00\n triangleArea(1, 2, 10) == -1\n */\nconst triangleArea = (a, b, c) => {\n", "canonical_solution": " if (a + b <= c || a + c <= b || b + c <= a)\n return -1;\n var s = (a + b + c) / 2;\n var area = Math.pow(s * (s - a) * (s - b) * (s - c), 0.5);\n area = area.toFixed(2);\n return area;\n}\n\n", "test": "const testTriangleArea = () => {\n console.assert(triangleArea(3, 4, 5) == 6.0)\n console.assert(triangleArea(1, 2, 10) == -1)\n console.assert(triangleArea(4, 8, 5) == 8.18)\n console.assert(triangleArea(2, 2, 2) == 1.73)\n console.assert(triangleArea(1, 2, 3) == -1)\n console.assert(triangleArea(10, 5, 7) == 16.25)\n console.assert(triangleArea(2, 6, 3) == -1)\n console.assert(triangleArea(1, 1, 1) == 0.43)\n console.assert(triangleArea(2, 2, 10) == -1)\n}\n\ntestTriangleArea()\n", "declaration": "\nconst triangleArea = (a, b, c) => {\n", "example_test": "const testTriangleArea = () => {\n console.assert(triangleArea(3, 4, 5) == 6.0)\n console.assert(triangleArea(1, 2, 10) == -1)\n}\ntestTriangleArea()\n", "buggy_solution": " if (a + b <= c || a + c <= b || b + c <= a)\n return -1;\n var s = (a + b + c);\n var area = Math.pow(s * (s - a) * (s - b) * (s - c), 0.5);\n area = area.toFixed(2);\n return area;\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "triangleArea", "signature": "const triangleArea = (a, b, c)", "docstring": "Given the lengths of the three sides of a triangle. Return the area of\nthe triangle rounded to 2 decimal points if the three sides form a valid triangle.\nOtherwise return -1\nThree sides make a valid triangle when the sum of any two sides is greater\nthan the third side.\nExample:\ntriangleArea(3, 4, 5) == 6.00\ntriangleArea(1, 2, 10) == -1", "instruction": "Write a JavaScript function `const triangleArea = (a, b, c)` to solve the following problem:\nGiven the lengths of the three sides of a triangle. Return the area of\nthe triangle rounded to 2 decimal points if the three sides form a valid triangle.\nOtherwise return -1\nThree sides make a valid triangle when the sum of any two sides is greater\nthan the third side.\nExample:\ntriangleArea(3, 4, 5) == 6.00\ntriangleArea(1, 2, 10) == -1"} +{"task_id": "JavaScript/72", "prompt": "/*\n Write a function that returns true if the object q will fly, and false otherwise.\n The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w.\n\n Example:\n willItFly([1, 2], 5) \u279e false\n # 1+2 is less than the maximum possible weight, but it's unbalanced.\n\n willItFly([3, 2, 3], 1) \u279e false\n # it's balanced, but 3+2+3 is more than the maximum possible weight.\n\n willItFly([3, 2, 3], 9) \u279e true\n # 3+2+3 is less than the maximum possible weight, and it's balanced.\n\n willItFly([3], 5) \u279e true\n # 3 is less than the maximum possible weight, and it's balanced.\n */\nconst willItFly = (q, w) => {\n", "canonical_solution": " if (q.reduce(((prev, item) => prev + item), 0) > w)\n return false;\n var i = 0, j = q.length - 1;\n while (i < j) {\n if (q[i] != q[j])\n return false;\n i++;\n j--;\n }\n return true;\n}\n\n", "test": "const testWillItFly = () => {\n console.assert(willItFly([3, 2, 3], 9) === true)\n console.assert(willItFly([1, 2], 5) === false)\n console.assert(willItFly([3], 5) === true)\n console.assert(willItFly([3, 2, 3], 1) === false)\n console.assert(willItFly([1, 2, 3], 6) === false)\n console.assert(willItFly([5], 5) === true)\n}\n\ntestWillItFly()\n", "declaration": "\nconst willItFly = (q, w) => {\n", "example_test": "const testWillItFly = () => {\n console.assert(willItFly([3, 2, 3], 9) === true)\n console.assert(willItFly([1, 2], 5) === false)\n console.assert(willItFly([3], 5) === true)\n console.assert(willItFly([3, 2, 3], 1) === false)\n}\ntestWillItFly()\n", "buggy_solution": " if (q.reduce(((prev, item) => prev + item), 0) > w)\n return false;\n var i = 0, j = q.length - 1;\n while (i < j) {\n if (q[i] == q[j])\n return false;\n i++;\n j--;\n }\n return true;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "willItFly", "signature": "const willItFly = (q, w)", "docstring": "Write a function that returns true if the object q will fly, and false otherwise.\nThe object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w.\nExample:\nwillItFly([1, 2], 5) \u279e false\n# 1+2 is less than the maximum possible weight, but it's unbalanced.\nwillItFly([3, 2, 3], 1) \u279e false\n# it's balanced, but 3+2+3 is more than the maximum possible weight.\nwillItFly([3, 2, 3], 9) \u279e true\n# 3+2+3 is less than the maximum possible weight, and it's balanced.\nwillItFly([3], 5) \u279e true\n# 3 is less than the maximum possible weight, and it's balanced.", "instruction": "Write a JavaScript function `const willItFly = (q, w)` to solve the following problem:\nWrite a function that returns true if the object q will fly, and false otherwise.\nThe object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w.\nExample:\nwillItFly([1, 2], 5) \u279e false\n# 1+2 is less than the maximum possible weight, but it's unbalanced.\nwillItFly([3, 2, 3], 1) \u279e false\n# it's balanced, but 3+2+3 is more than the maximum possible weight.\nwillItFly([3, 2, 3], 9) \u279e true\n# 3+2+3 is less than the maximum possible weight, and it's balanced.\nwillItFly([3], 5) \u279e true\n# 3 is less than the maximum possible weight, and it's balanced."} +{"task_id": "JavaScript/73", "prompt": "/*\n Given an array arr of integers, find the minimum number of elements that\n need to be changed to make the array palindromic. A palindromic array is an array that\n is read the same backwards and forwards. In one change, you can change one element to any other element.\n\n For example:\n smallestChange([1,2,3,5,4,7,9,6]) == 4\n smallestChange([1, 2, 3, 4, 3, 2, 2]) == 1\n smallestChange([1, 2, 3, 2, 1]) == 0\n */\nconst smallestChange = (arr) => {\n", "canonical_solution": " var ans = 0;\n for (let i = 0; i < Math.floor(arr.length / 2); i++)\n if (arr[i] != arr.at(-i - 1))\n ans++;\n return ans;\n}\n\n", "test": "const testSmallestChange = () => {\n console.assert(smallestChange([1, 2, 3, 5, 4, 7, 9, 6]) === 4)\n console.assert(smallestChange([1, 2, 3, 4, 3, 2, 2]) === 1)\n console.assert(smallestChange([1, 4, 2]) === 1)\n console.assert(smallestChange([1, 4, 4, 2]) === 1)\n console.assert(smallestChange([1, 2, 3, 2, 1]) === 0)\n console.assert(smallestChange([3, 1, 1, 3]) === 0)\n console.assert(smallestChange([1]) === 0)\n console.assert(smallestChange([0, 1]) === 1)\n}\n\ntestSmallestChange()\n", "declaration": "\nconst smallestChange = (arr) => {\n", "example_test": "const testSmallestChange = () => {\n console.assert(smallestChange([1, 2, 3, 5, 4, 7, 9, 6]) === 4)\n console.assert(smallestChange([1, 2, 3, 4, 3, 2, 2]) === 1)\n console.assert(smallestChange([1, 2, 3, 2, 1]) === 0)\n console.assert(smallestChange([3, 1, 1, 3]) === 0)\n}\ntestSmallestChange()\n", "buggy_solution": " var ans = 0;\n for (let i = 0; i < Math.floor(arr.length / 2); i++)\n if (ans != arr.at(-i - 1))\n ans++;\n return ans;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "smallestChange", "signature": "const smallestChange = (arr)", "docstring": "Given an array arr of integers, find the minimum number of elements that\nneed to be changed to make the array palindromic. A palindromic array is an array that\nis read the same backwards and forwards. In one change, you can change one element to any other element.\nFor example:\nsmallestChange([1,2,3,5,4,7,9,6]) == 4\nsmallestChange([1, 2, 3, 4, 3, 2, 2]) == 1\nsmallestChange([1, 2, 3, 2, 1]) == 0", "instruction": "Write a JavaScript function `const smallestChange = (arr)` to solve the following problem:\nGiven an array arr of integers, find the minimum number of elements that\nneed to be changed to make the array palindromic. A palindromic array is an array that\nis read the same backwards and forwards. In one change, you can change one element to any other element.\nFor example:\nsmallestChange([1,2,3,5,4,7,9,6]) == 4\nsmallestChange([1, 2, 3, 4, 3, 2, 2]) == 1\nsmallestChange([1, 2, 3, 2, 1]) == 0"} +{"task_id": "JavaScript/74", "prompt": "/*\n Write a function that accepts two lists of strings and returns the list that has\n total number of chars in the all strings of the list less than the other list.\n\n if the two lists have the same number of chars, return the first list.\n\n Examples\n totalMatch([], []) \u279e []\n totalMatch(['hi', 'admin'], ['hI', 'Hi']) \u279e ['hI', 'Hi']\n totalMatch(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) \u279e ['hi', 'admin']\n totalMatch(['hi', 'admin'], ['hI', 'hi', 'hi']) \u279e ['hI', 'hi', 'hi']\n totalMatch(['4'], ['1', '2', '3', '4', '5']) \u279e ['4']\n */\nconst totalMatch = (lst1, lst2) => {\n", "canonical_solution": " var l1 = lst1.reduce(((prev, item) => prev + item.length), 0);\n var l2 = lst2.reduce(((prev, item) => prev + item.length), 0);\n if (l1 <= l2)\n return lst1;\n else\n return lst2;\n}\n\n", "test": "const testTotalMatch = () => {\n console.assert(JSON.stringify(totalMatch([], [])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(totalMatch(['hi', 'admin'], ['hi', 'hi'])) ===\n JSON.stringify(['hi', 'hi'])\n )\n console.assert(\n JSON.stringify(\n totalMatch(['hi', 'admin'], ['hi', 'hi', 'admin', 'project'])\n ) === JSON.stringify(['hi', 'admin'])\n )\n console.assert(\n JSON.stringify(totalMatch(['4'], ['1', '2', '3', '4', '5'])) ===\n JSON.stringify(['4'])\n )\n console.assert(\n JSON.stringify(totalMatch(['hi', 'admin'], ['hI', 'Hi'])) ===\n JSON.stringify(['hI', 'Hi'])\n )\n console.assert(\n JSON.stringify(totalMatch(['hi', 'admin'], ['hI', 'hi', 'hi'])) ===\n JSON.stringify(['hI', 'hi', 'hi'])\n )\n console.assert(\n JSON.stringify(totalMatch(['hi', 'admin'], ['hI', 'hi', 'hii'])) ===\n JSON.stringify(['hi', 'admin'])\n )\n console.assert(\n JSON.stringify(totalMatch([], ['this'])) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(totalMatch(['this'], [])) === JSON.stringify([])\n )\n}\n\ntestTotalMatch()\n", "declaration": "\nconst totalMatch = (lst1, lst2) => {\n", "example_test": "const testTotalMatch = () => {\n console.assert(JSON.stringify(totalMatch([], [])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(\n totalMatch(['hi', 'admin'], ['hi', 'hi', 'admin', 'project'])\n ) === JSON.stringify(['hi', 'admin'])\n )\n console.assert(\n JSON.stringify(totalMatch(['4'], ['1', '2', '3', '4', '5'])) ===\n JSON.stringify(['4'])\n )\n console.assert(\n JSON.stringify(totalMatch(['hi', 'admin'], ['hI', 'Hi'])) ===\n JSON.stringify(['hI', 'Hi'])\n )\n console.assert(\n JSON.stringify(totalMatch(['hi', 'admin'], ['hI', 'hi', 'hi'])) ===\n JSON.stringify(['hI', 'hi', 'hi'])\n )\n}\ntestTotalMatch()\n", "buggy_solution": " var l1 = lst1.reduce(((prev, item) => prev + item.length), 0);\n var l2 = lst2.reduce(((prev, item) => prev + item.length), 0);\n if (l1 <= l2)\n return lst2;\n else\n return lst1;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "totalMatch", "signature": "const totalMatch = (lst1, lst2)", "docstring": "Write a function that accepts two lists of strings and returns the list that has\ntotal number of chars in the all strings of the list less than the other list.\nif the two lists have the same number of chars, return the first list.\nExamples\ntotalMatch([], []) \u279e []\ntotalMatch(['hi', 'admin'], ['hI', 'Hi']) \u279e ['hI', 'Hi']\ntotalMatch(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) \u279e ['hi', 'admin']\ntotalMatch(['hi', 'admin'], ['hI', 'hi', 'hi']) \u279e ['hI', 'hi', 'hi']\ntotalMatch(['4'], ['1', '2', '3', '4', '5']) \u279e ['4']", "instruction": "Write a JavaScript function `const totalMatch = (lst1, lst2)` to solve the following problem:\nWrite a function that accepts two lists of strings and returns the list that has\ntotal number of chars in the all strings of the list less than the other list.\nif the two lists have the same number of chars, return the first list.\nExamples\ntotalMatch([], []) \u279e []\ntotalMatch(['hi', 'admin'], ['hI', 'Hi']) \u279e ['hI', 'Hi']\ntotalMatch(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) \u279e ['hi', 'admin']\ntotalMatch(['hi', 'admin'], ['hI', 'hi', 'hi']) \u279e ['hI', 'hi', 'hi']\ntotalMatch(['4'], ['1', '2', '3', '4', '5']) \u279e ['4']"} +{"task_id": "JavaScript/75", "prompt": "/*Write a function that returns true if the given number is the multiplication of 3 prime numbers\n and false otherwise.\n Knowing that (a) is less then 100.\n Example:\n isMultiplyPrime(30) == true\n 30 = 2 * 3 * 5\n */\nconst isMultiplyPrime = (a) => {\n", "canonical_solution": " var isPrime = function (n) {\n for (let j = 2; j < n; j++)\n if (n % j == 0)\n return false;\n return true;\n }\n\n for (let i = 2; i < 101; i++) {\n if (!isPrime(i)) continue;\n for (let j = 2; j < 101; j++) {\n if (!isPrime(j)) continue;\n for (let k = 2; k < 101; k++) {\n if (!isPrime(k)) continue;\n if (i*j*k == a)\n return true;\n }\n }\n }\n return false;\n}\n\n", "test": "const testIsMultiplyPrime = () => {\n console.assert(isMultiplyPrime(5) === false)\n console.assert(isMultiplyPrime(30) === true)\n console.assert(isMultiplyPrime(8) === true)\n console.assert(isMultiplyPrime(10) === false)\n console.assert(isMultiplyPrime(125) === true)\n console.assert(isMultiplyPrime(3 * 5 * 7) === true)\n console.assert(isMultiplyPrime(3 * 6 * 7) === false)\n console.assert(isMultiplyPrime(9 * 9 * 9) === false)\n console.assert(isMultiplyPrime(11 * 9 * 9) === false)\n console.assert(isMultiplyPrime(11 * 13 * 7) === true)\n}\n\ntestIsMultiplyPrime()\n", "declaration": "\nconst isMultiplyPrime = (a) => {\n", "example_test": "const testIsMultiplyPrime = () => {\n console.assert(isMultiplyPrime(30) === true)\n}\ntestIsMultiplyPrime()\n", "buggy_solution": " var isPrime = function (n) {\n for (let j = 0; j < n; j++)\n if (n % j == 0)\n return false;\n return true;\n }\n\n for (let i = 2; i < 101; i++) {\n if (!isPrime(i)) continue;\n for (let j = 2; j < 101; j++) {\n if (!isPrime(j)) continue;\n for (let k = 2; k < 101; k++) {\n if (!isPrime(k)) continue;\n if (i*j*k == a)\n return true;\n }\n }\n }\n return false;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "isMultiplyPrime", "signature": "const isMultiplyPrime = (a)", "docstring": "Write a function that returns true if the given number is the multiplication of 3 prime numbers\nand false otherwise.\nKnowing that (a) is less then 100.\nExample:\nisMultiplyPrime(30) == true\n30 = 2 * 3 * 5", "instruction": "Write a JavaScript function `const isMultiplyPrime = (a)` to solve the following problem:\nWrite a function that returns true if the given number is the multiplication of 3 prime numbers\nand false otherwise.\nKnowing that (a) is less then 100.\nExample:\nisMultiplyPrime(30) == true\n30 = 2 * 3 * 5"} +{"task_id": "JavaScript/76", "prompt": "/*Your task is to write a function that returns true if a number x is a simple\n power of n and false in other cases.\n x is a simple power of n if n**int=x\n For example:\n isSimplePower(1, 4) => true\n isSimplePower(2, 2) => true\n isSimplePower(8, 2) => true\n isSimplePower(3, 2) => false\n isSimplePower(3, 1) => false\n isSimplePower(5, 3) => false\n */\nconst isSimplePower = (x, n) => {\n", "canonical_solution": " if (n == 1)\n return (x == 1);\n var power = 1;\n while (power < x)\n power = power * n;\n return (power == x);\n}\n\n", "test": "const testIsSimplePower = () => {\n console.assert(isSimplePower(1, 4) === true)\n console.assert(isSimplePower(2, 2) === true)\n console.assert(isSimplePower(8, 2) === true)\n console.assert(isSimplePower(3, 2) === false)\n console.assert(isSimplePower(3, 1) === false)\n console.assert(isSimplePower(5, 3) === false)\n console.assert(isSimplePower(16, 2) === true)\n console.assert(isSimplePower(143214, 16) === false)\n console.assert(isSimplePower(4, 2) === true)\n console.assert(isSimplePower(9, 3) === true)\n console.assert(isSimplePower(16, 4) === true)\n console.assert(isSimplePower(24, 2) === false)\n console.assert(isSimplePower(128, 4) === false)\n console.assert(isSimplePower(12, 6) === false)\n console.assert(isSimplePower(1, 1) === true)\n console.assert(isSimplePower(1, 12) === true)\n}\n\ntestIsSimplePower()\n", "declaration": "\nconst isSimplePower = (x, n) => {\n", "example_test": "const testIsSimplePower = () => {\n console.assert(isSimplePower(1, 4) === true)\n console.assert(isSimplePower(2, 2) === true)\n console.assert(isSimplePower(8, 2) === true)\n console.assert(isSimplePower(3, 2) === false)\n console.assert(isSimplePower(3, 1) === false)\n console.assert(isSimplePower(5, 3) === false)\n}\ntestIsSimplePower()\n", "buggy_solution": " if (n == 1)\n return (x == 1);\n var power = 1;\n while (n < x)\n power = power * n;\n return (power == x);\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "infinite loop", "entry_point": "isSimplePower", "signature": "const isSimplePower = (x, n)", "docstring": "Your task is to write a function that returns true if a number x is a simple\npower of n and false in other cases.\nx is a simple power of n if n**int=x\nFor example:\nisSimplePower(1, 4) => true\nisSimplePower(2, 2) => true\nisSimplePower(8, 2) => true\nisSimplePower(3, 2) => false\nisSimplePower(3, 1) => false\nisSimplePower(5, 3) => false", "instruction": "Write a JavaScript function `const isSimplePower = (x, n)` to solve the following problem:\nYour task is to write a function that returns true if a number x is a simple\npower of n and false in other cases.\nx is a simple power of n if n**int=x\nFor example:\nisSimplePower(1, 4) => true\nisSimplePower(2, 2) => true\nisSimplePower(8, 2) => true\nisSimplePower(3, 2) => false\nisSimplePower(3, 1) => false\nisSimplePower(5, 3) => false"} +{"task_id": "JavaScript/77", "prompt": "/*\n Write a function that takes an integer a and returns true\n if this ingeger is a cube of some integer number.\n Note: you may assume the input is always valid.\n Examples:\n iscube(1) ==> true\n iscube(2) ==> false\n iscube(-1) ==> true\n iscube(64) ==> true\n iscube(0) ==> true\n iscube(180) ==> false\n */\nconst iscube = (a) => {\n", "canonical_solution": " a = Math.abs(a);\n return (Math.pow(Math.round(Math.pow(a, 1.0 / 3.0)), 3) == a);\n}\n\n", "test": "const testIscube = () => {\n console.assert(true === iscube(1))\n console.assert(false === iscube(2))\n console.assert(true === iscube(-1))\n console.assert(true === iscube(64))\n console.assert(false === iscube(180))\n console.assert(true === iscube(1000))\n console.assert(true === iscube(0))\n console.assert(false === iscube(1729))\n}\n\ntestIscube()\n", "declaration": "\nconst iscube = (a) => {\n", "example_test": "const testIscube = () => {\n console.assert(true === iscube(1))\n console.assert(false === iscube(2))\n console.assert(true === iscube(-1))\n console.assert(true === iscube(64))\n console.assert(false === iscube(180))\n console.assert(true === iscube(0))\n}\ntestIscube()\n", "buggy_solution": " a = Math.abs(a);\n return (Math.round(Math.pow(a, 1.0 / 3.0)) == a);\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "iscube", "signature": "const iscube = (a)", "docstring": "Write a function that takes an integer a and returns true\nif this ingeger is a cube of some integer number.\nNote: you may assume the input is always valid.\nExamples:\niscube(1) ==> true\niscube(2) ==> false\niscube(-1) ==> true\niscube(64) ==> true\niscube(0) ==> true\niscube(180) ==> false", "instruction": "Write a JavaScript function `const iscube = (a)` to solve the following problem:\nWrite a function that takes an integer a and returns true\nif this ingeger is a cube of some integer number.\nNote: you may assume the input is always valid.\nExamples:\niscube(1) ==> true\niscube(2) ==> false\niscube(-1) ==> true\niscube(64) ==> true\niscube(0) ==> true\niscube(180) ==> false"} +{"task_id": "JavaScript/78", "prompt": "/*You have been tasked to write a function that receives\n a hexadecimal number as a string and counts the number of hexadecimal\n digits that are primes (prime number=== or a prime=== is a natural number\n greater than 1 that is not a product of two smaller natural numbers).\n Hexadecimal digits are 0=== 1=== 2=== 3=== 4=== 5=== 6=== 7=== 8=== 9=== A=== B=== C=== D=== E=== F.\n Prime numbers are 2=== 3=== 5=== 7=== 11=== 13=== 17===...\n So you have to determine a number of the following digits: 2=== 3=== 5=== 7===\n B (=decimal 11)=== D (=decimal 13).\n Note: you may assume the input is always correct or empty string===\n and symbols A===B===C===D===E===F are always uppercase.\n Examples:\n For num = \"AB\" the output should be 1.\n For num = \"1077E\" the output should be 2.\n For num = \"ABED1A33\" the output should be 4.\n For num = \"123456789ABCDEF0\" the output should be 6.\n For num = \"2020\" the output should be 2.\n */\nconst hexKey = (num) => {\n", "canonical_solution": " var primes = \"2357BD\",\n total = 0;\n for (let i = 0; i < num.length; i++)\n if (primes.includes(num[i]))\n total++;\n return total;\n}\n\n", "test": "const testHexKey = () => {\n console.assert(1 === hexKey('AB'))\n console.assert(2 === hexKey('1077E'))\n console.assert(4 === hexKey('ABED1A33'))\n console.assert(2 === hexKey('2020'))\n console.assert(6 === hexKey('123456789ABCDEF0'))\n console.assert(12 === hexKey('112233445566778899AABBCCDDEEFF00'))\n console.assert(0 === hexKey(''))\n}\n\ntestHexKey()\n", "declaration": "\nconst hexKey = (num) => {\n", "example_test": "const testHexKey = () => {\n console.assert(1 === hexKey('AB'))\n console.assert(2 === hexKey('1077E'))\n console.assert(4 === hexKey('ABED1A33'))\n console.assert(2 === hexKey('2020'))\n console.assert(6 === hexKey('123456789ABCDEF0'))\n}\ntestHexKey()\n", "buggy_solution": " var primes = \"2357BD\",\n total = 1;\n for (let i = 0; i < num.length; i++)\n if (primes.includes(num[i]))\n total++;\n return total;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "hexKey", "signature": "const hexKey = (num)", "docstring": "You have been tasked to write a function that receives\na hexadecimal number as a string and counts the number of hexadecimal\ndigits that are primes (prime number=== or a prime=== is a natural number\ngreater than 1 that is not a product of two smaller natural numbers).\nHexadecimal digits are 0=== 1=== 2=== 3=== 4=== 5=== 6=== 7=== 8=== 9=== A=== B=== C=== D=== E=== F.\nPrime numbers are 2=== 3=== 5=== 7=== 11=== 13=== 17===...\nSo you have to determine a number of the following digits: 2=== 3=== 5=== 7===\nB (=decimal 11)=== D (=decimal 13).\nNote: you may assume the input is always correct or empty string===\nand symbols A===B===C===D===E===F are always uppercase.\nExamples:\nFor num = \"AB\" the output should be 1.\nFor num = \"1077E\" the output should be 2.\nFor num = \"ABED1A33\" the output should be 4.\nFor num = \"123456789ABCDEF0\" the output should be 6.\nFor num = \"2020\" the output should be 2.", "instruction": "Write a JavaScript function `const hexKey = (num)` to solve the following problem:\nYou have been tasked to write a function that receives\na hexadecimal number as a string and counts the number of hexadecimal\ndigits that are primes (prime number=== or a prime=== is a natural number\ngreater than 1 that is not a product of two smaller natural numbers).\nHexadecimal digits are 0=== 1=== 2=== 3=== 4=== 5=== 6=== 7=== 8=== 9=== A=== B=== C=== D=== E=== F.\nPrime numbers are 2=== 3=== 5=== 7=== 11=== 13=== 17===...\nSo you have to determine a number of the following digits: 2=== 3=== 5=== 7===\nB (=decimal 11)=== D (=decimal 13).\nNote: you may assume the input is always correct or empty string===\nand symbols A===B===C===D===E===F are always uppercase.\nExamples:\nFor num = \"AB\" the output should be 1.\nFor num = \"1077E\" the output should be 2.\nFor num = \"ABED1A33\" the output should be 4.\nFor num = \"123456789ABCDEF0\" the output should be 6.\nFor num = \"2020\" the output should be 2."} +{"task_id": "JavaScript/79", "prompt": "/*You will be given a number in decimal form and your task is to convert it to\n binary format. The function should return a string, with each character representing a binary\n number. Each character in the string will be '0' or '1'.\n\n There will be an extra couple of characters 'db' at the beginning and at the end of the string.\n The extra characters are there to help with the format.\n\n Examples:\n decimalToBinary(15) # returns \"db1111db\"\n decimalToBinary(32) # returns \"db100000db\"\n */\nconst decimalToBinary = (decimal) => {\n", "canonical_solution": " return \"db\" + decimal.toString(2) + \"db\";\n}\n\n", "test": "const testDecimalToBinary = () => {\n console.assert(decimalToBinary(0) === 'db0db')\n console.assert(decimalToBinary(32) === 'db100000db')\n console.assert(decimalToBinary(103) === 'db1100111db')\n console.assert(decimalToBinary(15) === 'db1111db')\n}\n\ntestDecimalToBinary()\n", "declaration": "\nconst decimalToBinary = (decimal) => {\n", "example_test": "const testDecimalToBinary = () => {\n console.assert(decimalToBinary(32) === 'db100000db')\n console.assert(decimalToBinary(15) === 'db1111db')\n}\ntestDecimalToBinary()\n", "buggy_solution": " return \"db\" + decimal.toString(2) + \"d\";\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "decimalToBinary", "signature": "const decimalToBinary = (decimal)", "docstring": "You will be given a number in decimal form and your task is to convert it to\nbinary format. The function should return a string, with each character representing a binary\nnumber. Each character in the string will be '0' or '1'.\nThere will be an extra couple of characters 'db' at the beginning and at the end of the string.\nThe extra characters are there to help with the format.\nExamples:\ndecimalToBinary(15) # returns \"db1111db\"\ndecimalToBinary(32) # returns \"db100000db\"", "instruction": "Write a JavaScript function `const decimalToBinary = (decimal)` to solve the following problem:\nYou will be given a number in decimal form and your task is to convert it to\nbinary format. The function should return a string, with each character representing a binary\nnumber. Each character in the string will be '0' or '1'.\nThere will be an extra couple of characters 'db' at the beginning and at the end of the string.\nThe extra characters are there to help with the format.\nExamples:\ndecimalToBinary(15) # returns \"db1111db\"\ndecimalToBinary(32) # returns \"db100000db\""} +{"task_id": "JavaScript/80", "prompt": "/*You are given a string s.\n Your task is to check if the string is happy or not.\n A string is happy if its length is at least 3 and every 3 consecutive letters are distinct\n For example:\n isHappy(a) => false\n isHappy(aa) => false\n isHappy(abcd) => true\n isHappy(aabb) => false\n isHappy(adb) => true\n isHappy(xyy) => false\n */\nconst isHappy = (s) => {\n", "canonical_solution": " if (s.length < 3)\n return false;\n for (let i = 0; i < s.length - 2; i++)\n if (s[i] == s[i+1] || s[i+1] == s[i+2] || s[i] == s[i+2])\n return false;\n return true;\n}\n\n", "test": "const testIsHappy = () => {\n console.assert(isHappy('a') === false)\n console.assert(isHappy('aa') === false)\n console.assert(isHappy('abcd') === true)\n console.assert(isHappy('aabb') === false)\n console.assert(isHappy('adb') === true)\n console.assert(isHappy('xyy') === false)\n console.assert(isHappy('iopaxpoi') === true)\n console.assert(isHappy('iopaxioi') === false)\n}\n\ntestIsHappy()\n", "declaration": "\nconst isHappy = (s) => {\n", "example_test": "const testIsHappy = () => {\n console.assert(isHappy('a') === false)\n console.assert(isHappy('aa') === false)\n console.assert(isHappy('abcd') === true)\n console.assert(isHappy('aabb') === false)\n console.assert(isHappy('adb') === true)\n console.assert(isHappy('xyy') === false)\n}\ntestIsHappy()\n", "buggy_solution": " if (s.length < 3)\n return false;\n for (let i = 0; i < s.length - 2; i++)\n if (s[i] == s[i+1] && s[i+1] == s[i+2] && s[i] == s[i+2])\n return false;\n return true;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "isHappy", "signature": "const isHappy = (s)", "docstring": "You are given a string s.\nYour task is to check if the string is happy or not.\nA string is happy if its length is at least 3 and every 3 consecutive letters are distinct\nFor example:\nisHappy(a) => false\nisHappy(aa) => false\nisHappy(abcd) => true\nisHappy(aabb) => false\nisHappy(adb) => true\nisHappy(xyy) => false", "instruction": "Write a JavaScript function `const isHappy = (s)` to solve the following problem:\nYou are given a string s.\nYour task is to check if the string is happy or not.\nA string is happy if its length is at least 3 and every 3 consecutive letters are distinct\nFor example:\nisHappy(a) => false\nisHappy(aa) => false\nisHappy(abcd) => true\nisHappy(aabb) => false\nisHappy(adb) => true\nisHappy(xyy) => false"} +{"task_id": "JavaScript/81", "prompt": "/*It is the last week of the semester and the teacher has to give the grades\n to students. The teacher has been making her own algorithm for grading.\n The only problem is, she has lost the code she used for grading.\n She has given you a list of GPAs for some students and you have to write\n a function that can output a list of letter grades using the following table:\n GPA | Letter grade\n 4.0 A+\n > 3.7 A\n > 3.3 A-\n > 3.0 B+\n > 2.7 B\n > 2.3 B-\n > 2.0 C+\n > 1.7 C\n > 1.3 C-\n > 1.0 D+\n > 0.7 D\n > 0.0 D-\n 0.0 E\n\n\n Example:\n numericalLetterGrade([4.0, 3, 1.7, 2, 3.5]) ==> ['A+', 'B', 'C-', 'C', 'A-']\n */\nconst numericalLetterGrade = (grades) => {\n", "canonical_solution": " let letter_grade = []\n for (let i = 0, len = grades.length; i < len; i++) {\n let gpa = grades[i]\n if (gpa == 4.0) {\n letter_grade.push('A+')\n } else if (gpa > 3.7) {\n letter_grade.push('A')\n } else if (gpa > 3.3) {\n letter_grade.push('A-')\n } else if (gpa > 3.0) {\n letter_grade.push('B+')\n } else if (gpa > 2.7) {\n letter_grade.push('B')\n } else if (gpa > 2.3) {\n letter_grade.push('B-')\n } else if (gpa > 2.0) {\n letter_grade.push('C+')\n } else if (gpa > 1.7) {\n letter_grade.push('C')\n } else if (gpa > 1.3) {\n letter_grade.push('C-')\n } else if (gpa > 1.0) {\n letter_grade.push('D+')\n } else if (gpa > 0.7) {\n letter_grade.push('D')\n } else if (gpa > 0.0) {\n letter_grade.push('D-')\n } else {\n letter_grade.push('E')\n }\n }\n return letter_grade\n}\n\n", "test": "const testNumericalLetterGrade = () => {\n console.assert(\n JSON.stringify(numericalLetterGrade([4.0, 3, 1.7, 2, 3.5])) ===\n JSON.stringify(['A+', 'B', 'C-', 'C', 'A-'])\n )\n console.assert(\n JSON.stringify(numericalLetterGrade([1.2])) === JSON.stringify(['D+'])\n )\n console.assert(\n JSON.stringify(numericalLetterGrade([0.5])) === JSON.stringify(['D-'])\n )\n console.assert(\n JSON.stringify(numericalLetterGrade([0.0])) === JSON.stringify(['E'])\n )\n console.assert(\n JSON.stringify(numericalLetterGrade([1, 0.3, 1.5, 2.8, 3.3])) ===\n JSON.stringify(['D', 'D-', 'C-', 'B', 'B+'])\n )\n console.assert(\n JSON.stringify(numericalLetterGrade([0, 0.7])) ===\n JSON.stringify(['E', 'D-'])\n )\n}\n\ntestNumericalLetterGrade()\n", "declaration": "\nconst numericalLetterGrade = (grades) => {\n", "example_test": "const testNumericalLetterGrade = () => {\n console.assert(\n JSON.stringify(numericalLetterGrade([4.0, 3, 1.7, 2, 3.5])) ===\n JSON.stringify(['A+', 'B', 'C-', 'C', 'A-'])\n )\n}\ntestNumericalLetterGrade()\n", "buggy_solution": " let letter_grade = []\n for (let i = 0, len = grades.length; i < len; i++) {\n let gpa = grades[i]\n if (gpa == 4.0) {\n letter_grade.push('A+')\n } else if (gpa > 3.7) {\n letter_grade.push('A')\n } else if (gpa > 3.3) {\n letter_grade.push('A-')\n } else if (gpa > 3.0) {\n letter_grade.push('B+')\n } else if (gpa > 2.7) {\n letter_grade.push('B')\n } else if (gpa > 2.3) {\n letter_grade.push('B-')\n } else if (gpa > 2.0) {\n letter_grade.push('C+')\n } else if (gpa > 1.7) {\n letter_grade.push('C')\n } else if (gpa > 1.3) {\n letter_grade.push('C-')\n } else if (gpa > 1.0) {\n letter_grade.push('D+')\n } else if (gpa > 0.7) {\n letter_grade.push('D')\n } else if (gpa > 0.0) {\n letter_grade.push('D-')\n } else {\n letter_grade.push('E+')\n }\n }\n return letter_grade\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "numericalLetterGrade", "signature": "const numericalLetterGrade = (grades)", "docstring": "It is the last week of the semester and the teacher has to give the grades\nto students. The teacher has been making her own algorithm for grading.\nThe only problem is, she has lost the code she used for grading.\nShe has given you a list of GPAs for some students and you have to write\na function that can output a list of letter grades using the following table:\nGPA | Letter grade\n4.0 A+\n> 3.7 A\n> 3.3 A-\n> 3.0 B+\n> 2.7 B\n> 2.3 B-\n> 2.0 C+\n> 1.7 C\n> 1.3 C-\n> 1.0 D+\n> 0.7 D\n> 0.0 D-\n0.0 E\nExample:\nnumericalLetterGrade([4.0, 3, 1.7, 2, 3.5]) ==> ['A+', 'B', 'C-', 'C', 'A-']", "instruction": "Write a JavaScript function `const numericalLetterGrade = (grades)` to solve the following problem:\nIt is the last week of the semester and the teacher has to give the grades\nto students. The teacher has been making her own algorithm for grading.\nThe only problem is, she has lost the code she used for grading.\nShe has given you a list of GPAs for some students and you have to write\na function that can output a list of letter grades using the following table:\nGPA | Letter grade\n4.0 A+\n> 3.7 A\n> 3.3 A-\n> 3.0 B+\n> 2.7 B\n> 2.3 B-\n> 2.0 C+\n> 1.7 C\n> 1.3 C-\n> 1.0 D+\n> 0.7 D\n> 0.0 D-\n0.0 E\nExample:\nnumericalLetterGrade([4.0, 3, 1.7, 2, 3.5]) ==> ['A+', 'B', 'C-', 'C', 'A-']"} +{"task_id": "JavaScript/82", "prompt": "/*Write a function that takes a string and returns true if the string\n length is a prime number or false otherwise\n Examples\n primeLength('Hello') == true\n primeLength('abcdcba') == true\n primeLength('kittens') == true\n primeLength('orange') == false\n */\nconst primeLength = (string) => {\n", "canonical_solution": " let len = string.length\n if (len == 1 || len == 0) { return false }\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { return false }\n }\n return true\n}\n\n", "test": "const testPrimeLength = () => {\n console.assert(primeLength('Hello') === true)\n console.assert(primeLength('abcdcba') === true)\n console.assert(primeLength('kittens') === true)\n console.assert(primeLength('orange') === false)\n console.assert(primeLength('wow') === true)\n console.assert(primeLength('world') === true)\n console.assert(primeLength('MadaM') === true)\n console.assert(primeLength('Wow') === true)\n console.assert(primeLength('') === false)\n console.assert(primeLength('HI') === true)\n console.assert(primeLength('go') === true)\n console.assert(primeLength('gogo') === false)\n console.assert(primeLength('aaaaaaaaaaaaaaa') === false)\n console.assert(primeLength('Madam') === true)\n console.assert(primeLength('M') === false)\n console.assert(primeLength('0') === false)\n}\n\ntestPrimeLength()\n", "declaration": "\nconst primeLength = (string) => {\n", "example_test": "const testPrimeLength = () => {\n console.assert(primeLength('Hello') === true)\n console.assert(primeLength('abcdcba') === true)\n console.assert(primeLength('kittens') === true)\n console.assert(primeLength('orange') === false)\n}\ntestPrimeLength()\n", "buggy_solution": " let len = string.length\n if (len == 1 || len == 0) { return false }\n for (let i = 3; i * i <= len; i++) {\n if (len % i == 0) { return false }\n }\n return true\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "primeLength", "signature": "const primeLength = (string)", "docstring": "Write a function that takes a string and returns true if the string\nlength is a prime number or false otherwise\nExamples\nprimeLength('Hello') == true\nprimeLength('abcdcba') == true\nprimeLength('kittens') == true\nprimeLength('orange') == false", "instruction": "Write a JavaScript function `const primeLength = (string)` to solve the following problem:\nWrite a function that takes a string and returns true if the string\nlength is a prime number or false otherwise\nExamples\nprimeLength('Hello') == true\nprimeLength('abcdcba') == true\nprimeLength('kittens') == true\nprimeLength('orange') == false"} +{"task_id": "JavaScript/83", "prompt": "/*\n Given a positive integer n, return the count of the numbers of n-digit\n positive integers that start or end with 1.\n */\nconst startsOneEnds = (n) => {\n", "canonical_solution": " if (n == 1) { return 1 }\n let t = 18\n for (let i = 2; i < n; i++) {\n t = t * 10\n }\n return t\n}\n\n", "test": "const testStartsOneEnds = () => {\n console.assert(startsOneEnds(1) === 1)\n console.assert(startsOneEnds(2) === 18)\n console.assert(startsOneEnds(3) === 180)\n console.assert(startsOneEnds(4) === 1800)\n console.assert(startsOneEnds(5) === 18000)\n}\n\ntestStartsOneEnds()\n", "declaration": "\nconst startsOneEnds = (n) => {\n", "example_test": "", "buggy_solution": " if (n == 1) { return 1 }\n let t = 18\n for (let i = 2; i < n; i++) {\n t = t * i * 10\n }\n return t\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "startsOneEnds", "signature": "const startsOneEnds = (n)", "docstring": "Given a positive integer n, return the count of the numbers of n-digit\npositive integers that start or end with 1.", "instruction": "Write a JavaScript function `const startsOneEnds = (n)` to solve the following problem:\nGiven a positive integer n, return the count of the numbers of n-digit\npositive integers that start or end with 1."} +{"task_id": "JavaScript/84", "prompt": "/*Given a positive integer N, return the total sum of its digits in binary.\n \n Example\n For N = 1000, the sum of digits will be 1 the output should be \"1\".\n For N = 150, the sum of digits will be 6 the output should be \"110\".\n For N = 147, the sum of digits will be 12 the output should be \"1100\".\n \n Variables:\n @N integer\n Constraints: 0 \u2264 N \u2264 10000.\n Output:\n a string of binary number\n */\nconst solve = (N) => {\n", "canonical_solution": " let t = 0\n while (N > 0) {\n t += N % 10\n N = (N - N % 10) / 10\n }\n return t.toString(2)\n}\n\n", "test": "const testSolve = () => {\n console.assert(solve(1000) === '1')\n console.assert(solve(150) === '110')\n console.assert(solve(147) === '1100')\n console.assert(solve(333) === '1001')\n console.assert(solve(963) === '10010')\n}\n\ntestSolve()\n", "declaration": "\nconst solve = (N) => {\n", "example_test": "", "buggy_solution": " let t = 0\n while (N > 0) {\n t = N % 10\n N = (N - N % 10) / 10\n }\n return t.toString(2)\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "solve", "signature": "const solve = (N)", "docstring": "Given a positive integer N, return the total sum of its digits in binary.\nExample\nFor N = 1000, the sum of digits will be 1 the output should be \"1\".\nFor N = 150, the sum of digits will be 6 the output should be \"110\".\nFor N = 147, the sum of digits will be 12 the output should be \"1100\".\nVariables:\n@N integer\nConstraints: 0 \u2264 N \u2264 10000.\nOutput:\na string of binary number", "instruction": "Write a JavaScript function `const solve = (N)` to solve the following problem:\nGiven a positive integer N, return the total sum of its digits in binary.\nExample\nFor N = 1000, the sum of digits will be 1 the output should be \"1\".\nFor N = 150, the sum of digits will be 6 the output should be \"110\".\nFor N = 147, the sum of digits will be 12 the output should be \"1100\".\nVariables:\n@N integer\nConstraints: 0 \u2264 N \u2264 10000.\nOutput:\na string of binary number"} +{"task_id": "JavaScript/85", "prompt": "/*Given a non-empty list of integers lst. add the even elements that are at odd indices..\n\n\n Examples:\n add([4, 2, 6, 7]) ==> 2 \n */\nconst add = (lst) => {\n", "canonical_solution": " let t = 0\n for (let i = 1; i < lst.length; i += 2) {\n if (lst[i] % 2 == 0) {\n t += lst[i]\n }\n }\n return t\n}\n\n", "test": "const testAdd = () => {\n console.assert(add([4, 88]) === 88)\n console.assert(add([4, 5, 6, 7, 2, 122]) === 122)\n console.assert(add([4, 0, 6, 7]) === 0)\n console.assert(add([4, 4, 6, 8]) === 12)\n}\n\ntestAdd()\n", "declaration": "\nconst add = (lst) => {\n", "example_test": "const testAdd = () => {\n console.assert(add([4, 2, 6, 7]) === 2)\n}\ntestAdd()\n", "buggy_solution": " let t = 0\n for (let i = 1; i < lst.length; i += 1) {\n if (lst[i] % 2 == 0) {\n t += lst[i]\n }\n }\n return t\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "add", "signature": "const add = (lst)", "docstring": "Given a non-empty list of integers lst. add the even elements that are at odd indices..\nExamples:\nadd([4, 2, 6, 7]) ==> 2", "instruction": "Write a JavaScript function `const add = (lst)` to solve the following problem:\nGiven a non-empty list of integers lst. add the even elements that are at odd indices..\nExamples:\nadd([4, 2, 6, 7]) ==> 2"} +{"task_id": "JavaScript/86", "prompt": "/*\n Write a function that takes a string and returns an ordered version of it.\n Ordered version of string, is a string where all words (separated by space)\n are replaced by a new word where all the characters arranged in\n ascending order based on ascii value.\n Note: You should keep the order of words and blank spaces in the sentence.\n\n For example:\n antiShuffle('Hi') returns 'Hi'\n antiShuffle('hello') returns 'ehllo'\n antiShuffle('Hello World!!!') returns 'Hello !!!Wdlor'\n */\nconst antiShuffle = (s) => {\n", "canonical_solution": " let arr = s.split(/\\s/)\n for (let i = 0; i < arr.length; i++) {\n for (let j = 0; j < arr[i].length; j++) {\n let ind = j\n for (let k = j + 1; k < arr[i].length; k++) {\n if (arr[i][k].charCodeAt() < arr[i][ind].charCodeAt()) {\n ind = k\n }\n }\n if (ind > j) {\n arr[i] = arr[i].slice(0, j) + arr[i][ind] + arr[i].slice(j + 1, ind) + arr[i][j] + arr[i].slice(ind + 1, arr[i].length)\n }\n }\n }\n let t = ''\n for (let i = 0; i < arr.length; i++) {\n if (i > 0) {\n t = t + ' '\n }\n t = t + arr[i]\n }\n return t\n}\n\n", "test": "const testAntiShuffle = () => {\n console.assert(antiShuffle('Hi') === 'Hi')\n console.assert(antiShuffle('hello') === 'ehllo')\n console.assert(antiShuffle('number') === 'bemnru')\n console.assert(antiShuffle('abcd') === 'abcd')\n console.assert(antiShuffle('Hello World!!!') === 'Hello !!!Wdlor')\n console.assert(antiShuffle('') === '')\n console.assert(\n antiShuffle('Hi. My name is Mister Robot. How are you?') ===\n '.Hi My aemn is Meirst .Rboot How aer ?ouy'\n )\n}\n\ntestAntiShuffle()\n", "declaration": "\nconst antiShuffle = (s) => {\n", "example_test": "const testAntiShuffle = () => {\n console.assert(antiShuffle('Hi') === 'Hi')\n console.assert(antiShuffle('hello') === 'ehllo')\n console.assert(antiShuffle('Hello World!!!') === 'Hello !!!Wdlor')\n}\ntestAntiShuffle()\n", "buggy_solution": " let arr = s.split(/\\s/)\n for (let i = 0; i < arr.length; i++) {\n for (let j = 0; j < arr[i].length; j++) {\n let ind = j\n for (let k = j + 1; k < arr[i].length; k++) {\n if (arr[i][k].charCodeAt() < arr[i][ind].charCodeAt()) {\n ind = k\n }\n }\n if (ind > j) {\n arr[i] = arr[i].slice(0, j) + arr[i][ind] + arr[i].slice(j + 1, ind) + arr[i][j] + arr[i].slice(ind + 1, arr[i].length)\n }\n }\n }\n let t = ''\n for (let i = 0; i < arr.length; i++) {\n t = t + arr[i]\n }\n return t\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "antiShuffle", "signature": "const antiShuffle = (s)", "docstring": "Write a function that takes a string and returns an ordered version of it.\nOrdered version of string, is a string where all words (separated by space)\nare replaced by a new word where all the characters arranged in\nascending order based on ascii value.\nNote: You should keep the order of words and blank spaces in the sentence.\nFor example:\nantiShuffle('Hi') returns 'Hi'\nantiShuffle('hello') returns 'ehllo'\nantiShuffle('Hello World!!!') returns 'Hello !!!Wdlor'", "instruction": "Write a JavaScript function `const antiShuffle = (s)` to solve the following problem:\nWrite a function that takes a string and returns an ordered version of it.\nOrdered version of string, is a string where all words (separated by space)\nare replaced by a new word where all the characters arranged in\nascending order based on ascii value.\nNote: You should keep the order of words and blank spaces in the sentence.\nFor example:\nantiShuffle('Hi') returns 'Hi'\nantiShuffle('hello') returns 'ehllo'\nantiShuffle('Hello World!!!') returns 'Hello !!!Wdlor'"} +{"task_id": "JavaScript/87", "prompt": "/*\n You are given a 2 dimensional data, as a nested lists,\n which is similar to matrix, however, unlike matrices,\n each row may contain a different number of columns.\n Given lst, and integer x, find integers x in the list,\n and return list of tuples, [(x1, y1), (x2, y2) ...] such that\n each tuple is a coordinate - (row, columns), starting with 0.\n Sort coordinates initially by rows in ascending order.\n Also, sort coordinates of the row by columns in descending order.\n \n Examples:\n getRow([\n [1,2,3,4,5,6],\n [1,2,3,4,1,6],\n [1,2,3,4,5,1]\n ], 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]\n getRow([], 1) == []\n getRow([[], [1], [1, 2, 3]], 3) == [(2, 2)]\n */\nconst getRow = (lst, x) => {\n", "canonical_solution": " let t = []\n for (let i = 0; i < lst.length; i++) {\n for (let j = lst[i].length - 1; j >= 0; j--) {\n if (lst[i][j] == x) {\n t.push((i, j))\n }\n }\n }\n return t\n}\n\n", "test": "const testGetRow = () => {\n console.assert(\n JSON.stringify(\n getRow(\n [\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 1, 6],\n [1, 2, 3, 4, 5, 1],\n ],\n 1\n )\n ) === JSON.stringify([(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)])\n )\n console.assert(\n JSON.stringify(\n getRow(\n [\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n ],\n 2\n )\n ) === JSON.stringify([(0, 1), (1, 1), (2, 1), (3, 1), (4, 1), (5, 1)])\n )\n console.assert(\n JSON.stringify(\n getRow(\n [\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n [1, 1, 3, 4, 5, 6],\n [1, 2, 1, 4, 5, 6],\n [1, 2, 3, 1, 5, 6],\n [1, 2, 3, 4, 1, 6],\n [1, 2, 3, 4, 5, 1],\n ],\n 1\n )\n ) ===\n JSON.stringify([\n (0, 0),\n (1, 0),\n (2, 1),\n (2, 0),\n (3, 2),\n (3, 0),\n (4, 3),\n (4, 0),\n (5, 4),\n (5, 0),\n (6, 5),\n (6, 0),\n ])\n )\n console.assert(JSON.stringify(getRow([], 1)) === JSON.stringify([]))\n console.assert(JSON.stringify(getRow([[1]], 2)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(getRow([[], [1], [1, 2, 3]], 3)) === JSON.stringify([(2, 2)])\n )\n}\n\ntestGetRow()\n", "declaration": "\nconst getRow = (lst, x) => {\n", "example_test": "const testGetRow = () => {\n console.assert(\n JSON.stringify(\n getRow(\n [\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 1, 6],\n [1, 2, 3, 4, 5, 1],\n ],\n 1\n )\n ) === JSON.stringify([(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)])\n )\n console.assert(JSON.stringify(getRow([], 1)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(getRow([[], [1], [1, 2, 3]], 3)) === JSON.stringify([(2, 2)])\n )\n}\ntestGetRow()\n", "buggy_solution": " let t = []\n for (let i = 0; i < lst.length; i++) {\n for (let j = lst[i].length - 1; j >= 0; j--) {\n if (lst[i][j] == x) {\n t.push((j, i))\n }\n }\n }\n return t\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "getRow", "signature": "const getRow = (lst, x)", "docstring": "You are given a 2 dimensional data, as a nested lists,\nwhich is similar to matrix, however, unlike matrices,\neach row may contain a different number of columns.\nGiven lst, and integer x, find integers x in the list,\nand return list of tuples, [(x1, y1), (x2, y2) ...] such that\neach tuple is a coordinate - (row, columns), starting with 0.\nSort coordinates initially by rows in ascending order.\nAlso, sort coordinates of the row by columns in descending order.\nExamples:\ngetRow([\n[1,2,3,4,5,6],\n[1,2,3,4,1,6],\n[1,2,3,4,5,1]\n], 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]\ngetRow([], 1) == []\ngetRow([[], [1], [1, 2, 3]], 3) == [(2, 2)]", "instruction": "Write a JavaScript function `const getRow = (lst, x)` to solve the following problem:\nYou are given a 2 dimensional data, as a nested lists,\nwhich is similar to matrix, however, unlike matrices,\neach row may contain a different number of columns.\nGiven lst, and integer x, find integers x in the list,\nand return list of tuples, [(x1, y1), (x2, y2) ...] such that\neach tuple is a coordinate - (row, columns), starting with 0.\nSort coordinates initially by rows in ascending order.\nAlso, sort coordinates of the row by columns in descending order.\nExamples:\ngetRow([\n[1,2,3,4,5,6],\n[1,2,3,4,1,6],\n[1,2,3,4,5,1]\n], 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]\ngetRow([], 1) == []\ngetRow([[], [1], [1, 2, 3]], 3) == [(2, 2)]"} +{"task_id": "JavaScript/88", "prompt": "/*\n Given an array of non-negative integers, return a copy of the given array after sorting,\n you will sort the given array in ascending order if the sum( first index value, last index value) is odd,\n or sort it in descending order if the sum( first index value, last index value) is even.\n\n Note:\n * don't change the given array.\n\n Examples:\n * sortArray([]) => []\n * sortArray([5]) => [5]\n * sortArray([2, 4, 3, 0, 1, 5]) => [0, 1, 2, 3, 4, 5]\n * sortArray([2, 4, 3, 0, 1, 5, 6]) => [6, 5, 4, 3, 2, 1, 0]\n */\nconst sortArray = (array) => {\n", "canonical_solution": " let arr = array\n let tot = arr[0] + arr[arr.length-1]\n for (let j = 0; j < arr.length; j++) {\n let ind = j\n for (let k = j + 1; k < arr.length; k++) {\n if ((tot % 2 == 1 && arr[k] < arr[ind]) || (tot % 2 == 0 && arr[k] > arr[ind])) {\n ind = k\n }\n }\n let tmp = arr[j]\n arr[j] = arr[ind]\n arr[ind] = tmp\n }\n return arr\n}\n\n", "test": "const testSortArray = () => {\n console.assert(JSON.stringify(sortArray([])) === JSON.stringify([]))\n console.assert(JSON.stringify(sortArray([5])) === JSON.stringify([5]))\n console.assert(JSON.stringify(sortArray([2, 4, 3, 0, 1, 5])) === JSON.stringify([0, 1, 2, 3, 4, 5]))\n console.assert(JSON.stringify(sortArray([2, 4, 3, 0, 1, 5, 6])) === JSON.stringify([6, 5, 4, 3, 2, 1, 0]))\n console.assert(JSON.stringify(sortArray([2, 1])) === JSON.stringify([1, 2]))\n console.assert(JSON.stringify(sortArray([15, 42, 87, 32, 11, 0])) === JSON.stringify([0, 11, 15, 32, 42, 87]))\n console.assert(JSON.stringify(sortArray([21, 14, 23, 11])) === JSON.stringify([23, 21, 14, 11]))\n}\n\ntestSortArray()\n", "declaration": "\nconst sortArray = (array) => {\n", "example_test": "const testSortArray = () => {\n console.assert(JSON.stringify(sortArray([])) === JSON.stringify([]))\n console.assert(JSON.stringify(sortArray([5])) === JSON.stringify([5]))\n console.assert(JSON.stringify(sortArray([2, 4, 3, 0, 1, 5])) === JSON.stringify([0, 1, 2, 3, 4, 5]))\n console.assert(JSON.stringify(sortArray([2, 4, 3, 0, 1, 5, 6])) === JSON.stringify([6, 5, 4, 3, 2, 1, 0]))\n}\ntestSortArray()\n", "buggy_solution": " let arr = array\n let tot = arr[0] + arr[arr.length-1]\n for (let j = 0; j < arr.length; j++) {\n let ind = j\n for (let k = j + 1; k < arr.length; k++) {\n if ((tot % 2 == 1 && arr[k] < arr[ind]) || (tot % 2 != 0 && arr[k] > arr[ind])) {\n ind = k\n }\n }\n let tmp = arr[j]\n arr[j] = arr[ind]\n arr[ind] = tmp\n }\n return arr\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "sortArray", "signature": "const sortArray = (array)", "docstring": "Given an array of non-negative integers, return a copy of the given array after sorting,\nyou will sort the given array in ascending order if the sum( first index value, last index value) is odd,\nor sort it in descending order if the sum( first index value, last index value) is even.\nNote:\n* don't change the given array.\nExamples:\n* sortArray([]) => []\n* sortArray([5]) => [5]\n* sortArray([2, 4, 3, 0, 1, 5]) => [0, 1, 2, 3, 4, 5]\n* sortArray([2, 4, 3, 0, 1, 5, 6]) => [6, 5, 4, 3, 2, 1, 0]", "instruction": "Write a JavaScript function `const sortArray = (array)` to solve the following problem:\nGiven an array of non-negative integers, return a copy of the given array after sorting,\nyou will sort the given array in ascending order if the sum( first index value, last index value) is odd,\nor sort it in descending order if the sum( first index value, last index value) is even.\nNote:\n* don't change the given array.\nExamples:\n* sortArray([]) => []\n* sortArray([5]) => [5]\n* sortArray([2, 4, 3, 0, 1, 5]) => [0, 1, 2, 3, 4, 5]\n* sortArray([2, 4, 3, 0, 1, 5, 6]) => [6, 5, 4, 3, 2, 1, 0]"} +{"task_id": "JavaScript/89", "prompt": "/*Create a function encrypt that takes a string as an argument and\n returns a string encrypted with the alphabet being rotated. \n The alphabet should be rotated in a manner such that the letters \n shift down by two multiplied to two places.\n For example:\n encrypt('hi') returns 'lm'\n encrypt('asdfghjkl') returns 'ewhjklnop'\n encrypt('gf') returns 'kj'\n encrypt('et') returns 'ix'\n */\nconst encrypt = (s) => {\n", "canonical_solution": " let t = ''\n for (let i = 0; i < s.length; i++) {\n let p = s[i].charCodeAt() + 4\n if (p > 122) { p -= 26 }\n t += String.fromCharCode(p)\n }\n return t\n}\n\n", "test": "const testEncrypt = () => {\n console.assert(encrypt('hi') === 'lm')\n console.assert(encrypt('asdfghjkl') === 'ewhjklnop')\n console.assert(encrypt('gf') === 'kj')\n console.assert(encrypt('et') === 'ix')\n console.assert(encrypt('faewfawefaewg') === 'jeiajeaijeiak')\n console.assert(encrypt('hellomyfriend') === 'lippsqcjvmirh')\n console.assert(\n encrypt('dxzdlmnilfuhmilufhlihufnmlimnufhlimnufhfucufh') ===\n 'hbdhpqrmpjylqmpyjlpmlyjrqpmqryjlpmqryjljygyjl'\n )\n console.assert(encrypt('a') === 'e')\n}\n\ntestEncrypt()\n", "declaration": "\nconst encrypt = (s) => {\n", "example_test": "const testEncrypt = () => {\n console.assert(encrypt('hi') === 'lm')\n console.assert(encrypt('asdfghjkl') === 'ewhjklnop')\n console.assert(encrypt('gf') === 'kj')\n console.assert(encrypt('et') === 'ix')\n}\ntestEncrypt()\n", "buggy_solution": " let t = ''\n for (let i = 0; i < s.length; i++) {\n let p = s[i].charCodeAt() + 4\n if (p > 122) { p -= 24 }\n t += String.fromCharCode(p)\n }\n return t\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "encrypt", "signature": "const encrypt = (s)", "docstring": "Create a function encrypt that takes a string as an argument and\nreturns a string encrypted with the alphabet being rotated.\nThe alphabet should be rotated in a manner such that the letters\nshift down by two multiplied to two places.\nFor example:\nencrypt('hi') returns 'lm'\nencrypt('asdfghjkl') returns 'ewhjklnop'\nencrypt('gf') returns 'kj'\nencrypt('et') returns 'ix'", "instruction": "Write a JavaScript function `const encrypt = (s)` to solve the following problem:\nCreate a function encrypt that takes a string as an argument and\nreturns a string encrypted with the alphabet being rotated.\nThe alphabet should be rotated in a manner such that the letters\nshift down by two multiplied to two places.\nFor example:\nencrypt('hi') returns 'lm'\nencrypt('asdfghjkl') returns 'ewhjklnop'\nencrypt('gf') returns 'kj'\nencrypt('et') returns 'ix'"} +{"task_id": "JavaScript/90", "prompt": "/*\n You are given a list of integers.\n Write a function nextSmallest() that returns the 2nd smallest element of the list.\n Return null if there is no such element.\n \n nextSmallest([1, 2, 3, 4, 5]) == 2\n nextSmallest([5, 1, 4, 3, 2]) == 2\n nextSmallest([]) == null\n nextSmallest([1, 1]) == null\n */\nconst nextSmallest = (lst) => {\n", "canonical_solution": " let arr = lst\n for (let j = 0; j < arr.length; j++) {\n let ind = j\n for (let k = j + 1; k < arr.length; k++) {\n if (arr[k] < arr[ind]) {\n ind = k\n }\n }\n let tmp = arr[j]\n arr[j] = arr[ind]\n arr[ind] = tmp\n }\n let smallest = arr[0]\n let pt = 1\n while(ptsmallest){\n return arr[pt]\n }\n pt++\n }\n return null\n}\n\n", "test": "const testNextSmallest = () => {\n console.assert(nextSmallest([1, 2, 3, 4, 5]) === 2)\n console.assert(nextSmallest([5, 1, 4, 3, 2]) === 2)\n console.assert(nextSmallest([]) === null)\n console.assert(nextSmallest([1, 1]) === null)\n console.assert(nextSmallest([1, 1, 1, 1, 0]) === 1)\n console.assert(nextSmallest([1, 0 ** 0]) === null)\n console.assert(nextSmallest([-35, 34, 12, -45]) === -35)\n}\n\ntestNextSmallest()\n", "declaration": "\nconst nextSmallest = (lst) => {\n", "example_test": "const testNextSmallest = () => {\n console.assert(nextSmallest([1, 2, 3, 4, 5]) === 2)\n console.assert(nextSmallest([5, 1, 4, 3, 2]) === 2)\n console.assert(nextSmallest([]) === null)\n console.assert(nextSmallest([1, 1]) === null)\n}\ntestNextSmallest()\n", "buggy_solution": " let arr = lst\n for (let j = 0; j < arr.length; j++) {\n let ind = j\n for (let k = j + 1; k < arr.length; k++) {\n if (arr[k] < arr[ind]) {\n ind = k\n }\n }\n let tmp = arr[j]\n arr[j] = arr[ind]\n arr[ind] = tmp\n }\n let smallest = 0\n let pt = 0\n while(ptsmallest){\n return arr[pt]\n }\n pt++\n }\n return null\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "nextSmallest", "signature": "const nextSmallest = (lst)", "docstring": "You are given a list of integers.\nWrite a function nextSmallest() that returns the 2nd smallest element of the list.\nReturn null if there is no such element.\nnextSmallest([1, 2, 3, 4, 5]) == 2\nnextSmallest([5, 1, 4, 3, 2]) == 2\nnextSmallest([]) == null\nnextSmallest([1, 1]) == null", "instruction": "Write a JavaScript function `const nextSmallest = (lst)` to solve the following problem:\nYou are given a list of integers.\nWrite a function nextSmallest() that returns the 2nd smallest element of the list.\nReturn null if there is no such element.\nnextSmallest([1, 2, 3, 4, 5]) == 2\nnextSmallest([5, 1, 4, 3, 2]) == 2\nnextSmallest([]) == null\nnextSmallest([1, 1]) == null"} +{"task_id": "JavaScript/91", "prompt": "/*\n You'll be given a string of words, and your task is to count the number\n of boredoms. A boredom is a sentence that starts with the word \"I\".\n Sentences are delimited by '.', '?' or '!'.\n \n For example:\n >>> isBored(\"Hello world\")\n 0\n >>> isBored(\"The sky is blue. The sun is shining. I love this weather\")\n 1\n */\nconst isBored = (S) => {\n", "canonical_solution": " let t = 0\n if (S[0] == 'I' && S[1] == ' ') { t = 1 }\n for (let i = 0; i < S.length; i++) {\n if (S[i] == '.' || S[i] == '!' || S[i] == '?') {\n if (S[i + 1] == ' ' && S[i + 2] == 'I' && S[i + 3] == ' ') {\n t++\n }\n }\n }\n return t\n}\n\n", "test": "const testIsBored = () => {\n console.assert(isBored('Hello world') === 0)\n console.assert(isBored('Is the sky blue?') === 0)\n console.assert(isBored('I love It !') === 1)\n console.assert(isBored('bIt') === 0)\n console.assert(\n isBored('I feel good today. I will be productive. will kill It') === 2\n )\n console.assert(isBored('You and I are going for a walk') === 0)\n}\n\ntestIsBored()\n", "declaration": "\nconst isBored = (S) => {\n", "example_test": "const testIsBored = () => {\n console.assert(isBored('Hello world') === 0)\n console.assert(isBored('The sky is blue. The sun is shining. I love this weather') === 1)\n}\ntestIsBored()\n", "buggy_solution": " let t = 0\n if (S[0] == ' ' && S[1] == 'I') { t = 1 }\n for (let i = 0; i < S.length; i++) {\n if (S[i] == '.' || S[i] == '!' || S[i] == '?') {\n if (S[i + 1] == ' ' && S[i + 2] == 'I' && S[i + 3] == ' ') {\n t++\n }\n }\n }\n return t\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "isBored", "signature": "const isBored = (S)", "docstring": "You'll be given a string of words, and your task is to count the number\nof boredoms. A boredom is a sentence that starts with the word \"I\".\nSentences are delimited by '.', '?' or '!'.\nFor example:\n>>> isBored(\"Hello world\")\n0\n>>> isBored(\"The sky is blue. The sun is shining. I love this weather\")\n1", "instruction": "Write a JavaScript function `const isBored = (S)` to solve the following problem:\nYou'll be given a string of words, and your task is to count the number\nof boredoms. A boredom is a sentence that starts with the word \"I\".\nSentences are delimited by '.', '?' or '!'.\nFor example:\n>>> isBored(\"Hello world\")\n0\n>>> isBored(\"The sky is blue. The sun is shining. I love this weather\")\n1"} +{"task_id": "JavaScript/92", "prompt": "/* Create a function that takes 3 numbers.\n Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.\n Returns false in any other cases.\n Examples\n anyInt(5, 2, 7) \u279e true\n anyInt(3, 2, 2) \u279e false\n anyInt(3, -2, 1) \u279e true\n anyInt(3.6, -2.2, 2) \u279e false\n */\nconst anyInt = (x, y, z) => {\n", "canonical_solution": " if (x % 1 === 0 && y % 1 === 0 && z % 1 === 0 && (x + y === z || x + z === y || x === y + z)) {\n return true\n }\n return false\n}\n\n", "test": "const testAnyInt = () => {\n console.assert(anyInt(2, 3, 1) === true)\n console.assert(anyInt(2.5, 2, 3) === false)\n console.assert(anyInt(1.5, 5, 3.5) === false)\n console.assert(anyInt(2, 6, 2) === false)\n console.assert(anyInt(4, 2, 2) === true)\n console.assert(anyInt(2.2, 2.2, 2.2) === false)\n console.assert(anyInt(-4, 6, 2) === true)\n console.assert(anyInt(2, 1, 1) === true)\n console.assert(anyInt(3, 4, 7) === true)\n console.assert(anyInt(3.0, 4, 7) === true)\n}\n\ntestAnyInt()\n", "declaration": "\nconst anyInt = (x, y, z) => {\n", "example_test": "const testAnyInt = () => {\n console.assert(anyInt(5, 2, 7) === true)\n console.assert(anyInt(3, 2, 2) === false)\n console.assert(anyInt(3, -2, 1) === true)\n console.assert(anyInt(3.6, -2.2, 2) === false)\n}\ntestAnyInt()\n", "buggy_solution": " if (x % 1 === 0 && y % 1 === 0 && z % 1 === 0 && (x + y === z || x === y + z)) {\n return true\n }\n return false\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "anyInt", "signature": "const anyInt = (x, y, z)", "docstring": "Create a function that takes 3 numbers.\nReturns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.\nReturns false in any other cases.\nExamples\nanyInt(5, 2, 7) \u279e true\nanyInt(3, 2, 2) \u279e false\nanyInt(3, -2, 1) \u279e true\nanyInt(3.6, -2.2, 2) \u279e false", "instruction": "Write a JavaScript function `const anyInt = (x, y, z)` to solve the following problem:\nCreate a function that takes 3 numbers.\nReturns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.\nReturns false in any other cases.\nExamples\nanyInt(5, 2, 7) \u279e true\nanyInt(3, 2, 2) \u279e false\nanyInt(3, -2, 1) \u279e true\nanyInt(3.6, -2.2, 2) \u279e false"} +{"task_id": "JavaScript/93", "prompt": "/*\n Write a function that takes a message, and encodes in such a \n way that it swaps case of all letters, replaces all vowels in \n the message with the letter that appears 2 places ahead of that \n vowel in the english alphabet. \n Assume only letters. \n \n Examples:\n >>> encode('test')\n 'TGST'\n >>> encode('This is a message')\n 'tHKS KS C MGSSCGG'\n */\nconst encode = (message) => {\n", "canonical_solution": " let t = ''\n for (let i = 0; i < message.length; i++) {\n let p = message[i].charCodeAt()\n if (p > 96) { p -= 32 }\n else if (p!=32 && p < 96) { p += 32 }\n if (p == 65 || p == 97 || p == 69 || p == 101 || p == 73 || p == 105 || p == 79 || p == 111 || p == 85 || p == 117) { p += 2 }\n t += String.fromCharCode(p)\n }\n return t\n}\n\n", "test": "const testEncode = () => {\n console.assert(encode('TEST') === 'tgst')\n console.assert(encode('Mudasir') === 'mWDCSKR')\n console.assert(encode('YES') === 'ygs')\n console.assert(encode('This is a message') === 'tHKS KS C MGSSCGG')\n console.assert(\n encode('I DoNt KnOw WhAt tO WrItE') === 'k dQnT kNqW wHcT Tq wRkTg'\n )\n}\n\ntestEncode()\n", "declaration": "\nconst encode = (message) => {\n", "example_test": "const testEncode = () => {\n console.assert(encode('test') === 'TGST')\n console.assert(encode('This is a message') === 'tHKS KS C MGSSCGG')\n}\ntestEncode()\n", "buggy_solution": " let t = ''\n for (let i = 0; i < message.length; i++) {\n let p = message[i].charCodeAt()\n if (p > 96) { p -= 32 }\n else if (p!=32 && p < 96) { p += 32 }\n if (p == 65 || p == 97 || p == 69 || p == 101 || p == 73 || p == 105 || p == 79 || p == 111 || p == 85 || p == 117) { p += 2 }\n }\n return t\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "encode", "signature": "const encode = (message)", "docstring": "Write a function that takes a message, and encodes in such a\nway that it swaps case of all letters, replaces all vowels in\nthe message with the letter that appears 2 places ahead of that\nvowel in the english alphabet.\nAssume only letters.\nExamples:\n>>> encode('test')\n'TGST'\n>>> encode('This is a message')\n'tHKS KS C MGSSCGG'", "instruction": "Write a JavaScript function `const encode = (message)` to solve the following problem:\nWrite a function that takes a message, and encodes in such a\nway that it swaps case of all letters, replaces all vowels in\nthe message with the letter that appears 2 places ahead of that\nvowel in the english alphabet.\nAssume only letters.\nExamples:\n>>> encode('test')\n'TGST'\n>>> encode('This is a message')\n'tHKS KS C MGSSCGG'"} +{"task_id": "JavaScript/94", "prompt": "/*You are given a list of integers.\n You need to find the largest prime value and return the sum of its digits.\n\n Examples:\n For lst = [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3] the output should be 10\n For lst = [1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1] the output should be 25\n For lst = [1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3] the output should be 13\n For lst = [0,724,32,71,99,32,6,0,5,91,83,0,5,6] the output should be 11\n For lst = [0,81,12,3,1,21] the output should be 3\n For lst = [0,8,1,2,1,7] the output should be 7\n */\nconst skjkasdkd = (lst) => {\n", "canonical_solution": " let t = 0\n for (let i = 0; i < lst.length; i++) {\n let p = 1\n for (let j = 2; j * j <= lst[i]; j++) {\n if (lst[i] % j == 0) { p = 0; break }\n }\n if (p == 1 && lst[i] > t) { t = lst[i] }\n }\n let k = 0\n while (t != 0) {\n k += t % 10\n t = (t - t % 10) / 10\n }\n return k\n}\n\n", "test": "const testSkjkasdkd = () => {\n console.assert(\n skjkasdkd([\n 0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3,\n ]) === 10\n )\n\n console.assert(\n skjkasdkd([1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) === 25\n )\n\n console.assert(\n skjkasdkd([\n 1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3,\n ]) === 13\n )\n\n console.assert(\n skjkasdkd([0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) === 11\n )\n\n console.assert(skjkasdkd([0, 81, 12, 3, 1, 21]) === 3)\n\n console.assert(skjkasdkd([0, 8, 1, 2, 1, 7]) === 7)\n\n console.assert(skjkasdkd([8191]) === 19)\n console.assert(skjkasdkd([8191, 123456, 127, 7]) === 19)\n console.assert(skjkasdkd([127, 97, 8192]) === 10)\n}\n\ntestSkjkasdkd()\n", "declaration": "\nconst skjkasdkd = (lst) => {\n", "example_test": "const testSkjkasdkd = () => {\n console.assert(\n skjkasdkd([\n 0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3,\n ]) === 10\n )\n console.assert(\n skjkasdkd([1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) === 25\n )\n console.assert(\n skjkasdkd([\n 1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3,\n ]) === 13\n )\n console.assert(\n skjkasdkd([0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) === 11\n )\n console.assert(skjkasdkd([0, 81, 12, 3, 1, 21]) === 3)\n console.assert(skjkasdkd([0, 8, 1, 2, 1, 7]) === 7)\n}\ntestSkjkasdkd()\n", "buggy_solution": " let t = 0\n for (let i = 0; i < lst.length; i++) {\n let p = 1\n for (let j = 2; j * j <= lst[i]; j++) {\n if (lst[i] % j == 0) { p = 0; break }\n }\n if (p == 1 || lst[i] > t) { t = lst[i] }\n }\n let k = 0\n while (t != 0) {\n k += t % 10\n t = (t - t % 10) / 10\n }\n return k\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "skjkasdkd", "signature": "const skjkasdkd = (lst)", "docstring": "You are given a list of integers.\nYou need to find the largest prime value and return the sum of its digits.\nExamples:\nFor lst = [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3] the output should be 10\nFor lst = [1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1] the output should be 25\nFor lst = [1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3] the output should be 13\nFor lst = [0,724,32,71,99,32,6,0,5,91,83,0,5,6] the output should be 11\nFor lst = [0,81,12,3,1,21] the output should be 3\nFor lst = [0,8,1,2,1,7] the output should be 7", "instruction": "Write a JavaScript function `const skjkasdkd = (lst)` to solve the following problem:\nYou are given a list of integers.\nYou need to find the largest prime value and return the sum of its digits.\nExamples:\nFor lst = [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3] the output should be 10\nFor lst = [1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1] the output should be 25\nFor lst = [1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3] the output should be 13\nFor lst = [0,724,32,71,99,32,6,0,5,91,83,0,5,6] the output should be 11\nFor lst = [0,81,12,3,1,21] the output should be 3\nFor lst = [0,8,1,2,1,7] the output should be 7"} +{"task_id": "JavaScript/95", "prompt": "/*\n Given a dictionary, return true if all keys are strings in lower \n case or all keys are strings in upper case, else return false.\n The function should return false is the given dictionary is empty.\n Examples:\n checkDictCase({\"a\":\"apple\", \"b\":\"banana\"}) should return true.\n checkDictCase({\"a\":\"apple\", \"A\":\"banana\", \"B\":\"banana\"}) should return false.\n checkDictCase({\"a\":\"apple\", 8:\"banana\", \"a\":\"apple\"}) should return false.\n checkDictCase({\"Name\":\"John\", \"Age\":\"36\", \"City\":\"Houston\"}) should return false.\n checkDictCase({\"STATE\":\"NC\", \"ZIP\":\"12345\" }) should return true.\n */\nconst checkDictCase = (dict) => {\n", "canonical_solution": " let c = 0\n let lo = 1\n let hi = 1\n for (let key in dict) {\n c++\n for (let i = 0; i < key.length; i++) {\n if (key[i].charCodeAt() < 65 || key[i].charCodeAt() > 90) { hi = 0 }\n if (key[i].charCodeAt() < 97 || key[i].charCodeAt() > 122) { lo = 0 }\n }\n }\n if ((lo == 0 && hi == 0) || c == 0) { return false }\n return true\n}\n\n", "test": "const testCheckDictCase = () => {\n console.assert(checkDictCase({ p: 'pineapple', b: 'banana' }) === true)\n console.assert(\n checkDictCase({ p: 'pineapple', A: 'banana', B: 'banana' }) === false\n )\n console.assert(\n checkDictCase({ p: 'pineapple', 5: 'banana', a: 'apple' }) === false\n )\n console.assert(\n checkDictCase({ Name: 'John', Age: '36', City: 'Houston' }) === false\n )\n console.assert(checkDictCase({ STATE: 'NC', ZIP: '12345' }) === true)\n console.assert(checkDictCase({ fruit: 'Orange', taste: 'Sweet' }) === true)\n console.assert(checkDictCase({}) === false)\n}\n\ntestCheckDictCase()\n", "declaration": "\nconst checkDictCase = (dict) => {\n", "example_test": "const testCheckDictCase = () => {\n console.assert(checkDictCase({ p: 'pineapple', b: 'banana' }) === true)\n console.assert(\n checkDictCase({ p: 'pineapple', A: 'banana', B: 'banana' }) === false\n )\n console.assert(\n checkDictCase({ p: 'pineapple', 8: 'banana', a: 'apple' }) === false\n )\n console.assert(\n checkDictCase({ Name: 'John', Age: '36', City: 'Houston' }) === false\n )\n console.assert(checkDictCase({ STATE: 'NC', ZIP: '12345' }) === true)\n}\ntestCheckDictCase()\n", "buggy_solution": " let c = 0\n let lo = 1\n let hi = 1\n for (let key in dict) {\n c++\n for (let i = 0; i < key.length; i++) {\n if (key[i].charCodeAt() < 65 || key[i].charCodeAt() > 90) { hi = 0 }\n if (key[i].charCodeAt() < 97 || key[i].charCodeAt() > 122) { lo = 0 }\n }\n }\n if ((lo == 0 && hi == 0) && c == 0) { return false }\n return true\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "checkDictCase", "signature": "const checkDictCase = (dict)", "docstring": "Given a dictionary, return true if all keys are strings in lower\ncase or all keys are strings in upper case, else return false.\nThe function should return false is the given dictionary is empty.\nExamples:\ncheckDictCase({\"a\":\"apple\", \"b\":\"banana\"}) should return true.\ncheckDictCase({\"a\":\"apple\", \"A\":\"banana\", \"B\":\"banana\"}) should return false.\ncheckDictCase({\"a\":\"apple\", 8:\"banana\", \"a\":\"apple\"}) should return false.\ncheckDictCase({\"Name\":\"John\", \"Age\":\"36\", \"City\":\"Houston\"}) should return false.\ncheckDictCase({\"STATE\":\"NC\", \"ZIP\":\"12345\" }) should return true.", "instruction": "Write a JavaScript function `const checkDictCase = (dict)` to solve the following problem:\nGiven a dictionary, return true if all keys are strings in lower\ncase or all keys are strings in upper case, else return false.\nThe function should return false is the given dictionary is empty.\nExamples:\ncheckDictCase({\"a\":\"apple\", \"b\":\"banana\"}) should return true.\ncheckDictCase({\"a\":\"apple\", \"A\":\"banana\", \"B\":\"banana\"}) should return false.\ncheckDictCase({\"a\":\"apple\", 8:\"banana\", \"a\":\"apple\"}) should return false.\ncheckDictCase({\"Name\":\"John\", \"Age\":\"36\", \"City\":\"Houston\"}) should return false.\ncheckDictCase({\"STATE\":\"NC\", \"ZIP\":\"12345\" }) should return true."} +{"task_id": "JavaScript/96", "prompt": "/*Implement a function that takes an non-negative integer and returns an array of the first n\n integers that are prime numbers and less than n.\n for example:\n countUpTo(5) => [2,3]\n countUpTo(11) => [2,3,5,7]\n countUpTo(0) => []\n countUpTo(20) => [2,3,5,7,11,13,17,19]\n countUpTo(1) => []\n countUpTo(18) => [2,3,5,7,11,13,17]\n */\nconst countUpTo = (n) => {\n", "canonical_solution": " let t = []\n for (let i = 2; i < n; i++) {\n let p = 1\n for (let j = 2; j * j <= i; j++) {\n if (i % j == 0) { p = 0; break }\n }\n if (p == 1) { t.push(i) }\n }\n return t\n}\n\n", "test": "const testCountUpTo = () => {\n console.assert(JSON.stringify(countUpTo(5)) === JSON.stringify([2, 3]))\n console.assert(JSON.stringify(countUpTo(6)) === JSON.stringify([2, 3, 5]))\n console.assert(JSON.stringify(countUpTo(7)) === JSON.stringify([2, 3, 5]))\n console.assert(JSON.stringify(countUpTo(10)) === JSON.stringify([2, 3, 5, 7]))\n console.assert(JSON.stringify(countUpTo(0)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(countUpTo(22)) ===\n JSON.stringify([2, 3, 5, 7, 11, 13, 17, 19])\n )\n console.assert(JSON.stringify(countUpTo(1)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(countUpTo(18)) === JSON.stringify([2, 3, 5, 7, 11, 13, 17])\n )\n console.assert(\n JSON.stringify(countUpTo(47)) ===\n JSON.stringify([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43])\n )\n console.assert(\n JSON.stringify(countUpTo(101)) ===\n JSON.stringify([\n 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,\n 71, 73, 79, 83, 89, 97,\n ])\n )\n}\n\ntestCountUpTo()\n", "declaration": "\nconst countUpTo = (n) => {\n", "example_test": "const testCountUpTo = () => {\n console.assert(JSON.stringify(countUpTo(5)) === JSON.stringify([2, 3]))\n console.assert(JSON.stringify(countUpTo(11)) === JSON.stringify([2, 3, 5, 7]))\n console.assert(JSON.stringify(countUpTo(0)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(countUpTo(20)) ===\n JSON.stringify([2, 3, 5, 7, 11, 13, 17, 19])\n )\n console.assert(JSON.stringify(countUpTo(1)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(countUpTo(18)) === JSON.stringify([2, 3, 5, 7, 11, 13, 17])\n )\n}\ntestCountUpTo()\n", "buggy_solution": " let t = []\n for (let i = 2; i < n; i++) {\n let p = 1\n for (let j = 2; j * j <= i; j++) {\n if (j % i == 0) { p = 0; break }\n }\n if (p == 1) { t.push(i) }\n }\n return t\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "countUpTo", "signature": "const countUpTo = (n)", "docstring": "Implement a function that takes an non-negative integer and returns an array of the first n\nintegers that are prime numbers and less than n.\nfor example:\ncountUpTo(5) => [2,3]\ncountUpTo(11) => [2,3,5,7]\ncountUpTo(0) => []\ncountUpTo(20) => [2,3,5,7,11,13,17,19]\ncountUpTo(1) => []\ncountUpTo(18) => [2,3,5,7,11,13,17]", "instruction": "Write a JavaScript function `const countUpTo = (n)` to solve the following problem:\nImplement a function that takes an non-negative integer and returns an array of the first n\nintegers that are prime numbers and less than n.\nfor example:\ncountUpTo(5) => [2,3]\ncountUpTo(11) => [2,3,5,7]\ncountUpTo(0) => []\ncountUpTo(20) => [2,3,5,7,11,13,17,19]\ncountUpTo(1) => []\ncountUpTo(18) => [2,3,5,7,11,13,17]"} +{"task_id": "JavaScript/97", "prompt": "/*Complete the function that takes two integers and returns \n the product of their unit digits.\n Assume the input is always valid.\n Examples:\n multiply(148, 412) should return 16.\n multiply(19, 28) should return 72.\n multiply(2020, 1851) should return 0.\n multiply(14,-15) should return 20.\n */\nconst multiply = (a, b) => {\n", "canonical_solution": " if (a < 0) { a = -a }\n if (b < 0) { b = -b }\n return (a % 10) * (b % 10)\n}\n\n", "test": "const testMultiply = () => {\n console.assert(multiply(148, 412) === 16)\n console.assert(multiply(19, 28) === 72)\n console.assert(multiply(2020, 1851) === 0)\n console.assert(multiply(14, -15) === 20)\n console.assert(multiply(76, 67) === 42)\n console.assert(multiply(17, 27) === 49)\n console.assert(multiply(0, 1) === 0)\n console.assert(multiply(0, 0) === 0)\n}\n\ntestMultiply()\n", "declaration": "\nconst multiply = (a, b) => {\n", "example_test": "const testMultiply = () => {\n console.assert(multiply(148, 412) === 16)\n console.assert(multiply(19, 28) === 72)\n console.assert(multiply(2020, 1851) === 0)\n console.assert(multiply(14, -15) === 20)\n}\ntestMultiply()\n", "buggy_solution": " if (a < 0) { a = -a }\n if (b < 0) { b = -b }\n return (a % 10) * (b % 10) * a * b\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "multiply", "signature": "const multiply = (a, b)", "docstring": "Complete the function that takes two integers and returns\nthe product of their unit digits.\nAssume the input is always valid.\nExamples:\nmultiply(148, 412) should return 16.\nmultiply(19, 28) should return 72.\nmultiply(2020, 1851) should return 0.\nmultiply(14,-15) should return 20.", "instruction": "Write a JavaScript function `const multiply = (a, b)` to solve the following problem:\nComplete the function that takes two integers and returns\nthe product of their unit digits.\nAssume the input is always valid.\nExamples:\nmultiply(148, 412) should return 16.\nmultiply(19, 28) should return 72.\nmultiply(2020, 1851) should return 0.\nmultiply(14,-15) should return 20."} +{"task_id": "JavaScript/98", "prompt": "/*\n Given a string s, count the number of uppercase vowels in even indices.\n \n For example:\n countUpper('aBCdEf') returns 1\n countUpper('abcdefg') returns 0\n countUpper('dBBE') returns 0\n */\nconst countUpper = (s) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < s.length; i += 2) {\n if (s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U') { p++ }\n }\n return p\n}\n\n", "test": "const testCountUpper = () => {\n console.assert(countUpper('aBCdEf') === 1)\n console.assert(countUpper('abcdefg') === 0)\n console.assert(countUpper('dBBE') === 0)\n console.assert(countUpper('B') === 0)\n console.assert(countUpper('U') === 1)\n console.assert(countUpper('') === 0)\n console.assert(countUpper('EEEE') === 2)\n}\n\ntestCountUpper()\n", "declaration": "\nconst countUpper = (s) => {\n", "example_test": "const testCountUpper = () => {\n console.assert(countUpper('aBCdEf') === 1)\n console.assert(countUpper('abcdefg') === 0)\n console.assert(countUpper('dBBE') === 0)\n}\ntestCountUpper()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < s.length; i += 2) {\n if (s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U') { p += 2 }\n }\n return p\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "countUpper", "signature": "const countUpper = (s)", "docstring": "Given a string s, count the number of uppercase vowels in even indices.\nFor example:\ncountUpper('aBCdEf') returns 1\ncountUpper('abcdefg') returns 0\ncountUpper('dBBE') returns 0", "instruction": "Write a JavaScript function `const countUpper = (s)` to solve the following problem:\nGiven a string s, count the number of uppercase vowels in even indices.\nFor example:\ncountUpper('aBCdEf') returns 1\ncountUpper('abcdefg') returns 0\ncountUpper('dBBE') returns 0"} +{"task_id": "JavaScript/99", "prompt": "/* Create a function that takes a value (string) representing a number\n and returns the closest integer to it. If the number is equidistant\n from two integers, round it away from zero.\n Examples\n >>> closestInteger(\"10\")\n 10\n >>> closestInteger(\"15.3\")\n 15\n Note:\n Rounding away from zero means that if the given number is equidistant\n from two integers, the one you should return is the one that is the\n farthest from zero. For example closestInteger(\"14.5\") should\n return 15 and closestInteger(\"-14.5\") should return -15.\n */\nconst closestInteger = (value) => {\n", "canonical_solution": " value = Number(value)\n let t = value % 1\n if (t < 0.5 && t > -0.5) { value -= t }\n else { value += t }\n return value\n}\n\n", "test": "const testClosestInteger = () => {\n console.assert(closestInteger('10') === 10)\n console.assert(closestInteger('14.5') === 15)\n console.assert(closestInteger('-15.5') === -16)\n console.assert(closestInteger('15.3') === 15)\n console.assert(closestInteger('0') === 0)\n}\n\ntestClosestInteger()\n", "declaration": "\nconst closestInteger = (value) => {\n", "example_test": "const testClosestInteger = () => {\n console.assert(closestInteger('10') === 10)\n console.assert(closestInteger('15.3') === 15)\n}\ntestClosestInteger()\n", "buggy_solution": " value = Number(value)\n let t = value % 1\n if (t < 0.5 && t > -0.5) { value += t }\n else { value -= t }\n return value\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "closestInteger", "signature": "const closestInteger = (value)", "docstring": "Create a function that takes a value (string) representing a number\nand returns the closest integer to it. If the number is equidistant\nfrom two integers, round it away from zero.\nExamples\n>>> closestInteger(\"10\")\n10\n>>> closestInteger(\"15.3\")\n15\nNote:\nRounding away from zero means that if the given number is equidistant\nfrom two integers, the one you should return is the one that is the\nfarthest from zero. For example closestInteger(\"14.5\") should\nreturn 15 and closestInteger(\"-14.5\") should return -15.", "instruction": "Write a JavaScript function `const closestInteger = (value)` to solve the following problem:\nCreate a function that takes a value (string) representing a number\nand returns the closest integer to it. If the number is equidistant\nfrom two integers, round it away from zero.\nExamples\n>>> closestInteger(\"10\")\n10\n>>> closestInteger(\"15.3\")\n15\nNote:\nRounding away from zero means that if the given number is equidistant\nfrom two integers, the one you should return is the one that is the\nfarthest from zero. For example closestInteger(\"14.5\") should\nreturn 15 and closestInteger(\"-14.5\") should return -15."} +{"task_id": "JavaScript/100", "prompt": "/*\n Given a positive integer n, you have to make a pile of n levels of stones.\n The first level has n stones.\n The number of stones in the next level is:\n - the next odd number if n is odd.\n - the next even number if n is even.\n Return the number of stones in each level in a list, where element at index\n i represents the number of stones in the level (i+1).\n\n Examples:\n >>> makeAPile(3)\n [3, 5, 7]\n */\nconst makeAPile = (n) => {\n", "canonical_solution": " let t = []\n for (let i = n; i < n * 3; i += 2) {\n t.push(i)\n }\n return t\n}\n\n", "test": "const testMakeAPile = () => {\n console.assert(JSON.stringify(makeAPile(3)) === JSON.stringify([3, 5, 7]))\n console.assert(JSON.stringify(makeAPile(4)) === JSON.stringify([4, 6, 8, 10]))\n console.assert(\n JSON.stringify(makeAPile(5)) === JSON.stringify([5, 7, 9, 11, 13])\n )\n console.assert(\n JSON.stringify(makeAPile(6)) === JSON.stringify([6, 8, 10, 12, 14, 16])\n )\n console.assert(\n JSON.stringify(makeAPile(8)) ===\n JSON.stringify([8, 10, 12, 14, 16, 18, 20, 22])\n )\n}\n\ntestMakeAPile()\n", "declaration": "\nconst makeAPile = (n) => {\n", "example_test": "const testMakeAPile = () => {\n console.assert(JSON.stringify(makeAPile(3)) === JSON.stringify([3, 5, 7]))\n}\ntestMakeAPile()\n", "buggy_solution": " let t = []\n for (let i = n; i < n * 3; i += 2) {\n t.push(i)\n t.push(n)\n }\n return t\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "makeAPile", "signature": "const makeAPile = (n)", "docstring": "Given a positive integer n, you have to make a pile of n levels of stones.\nThe first level has n stones.\nThe number of stones in the next level is:\n- the next odd number if n is odd.\n- the next even number if n is even.\nReturn the number of stones in each level in a list, where element at index\ni represents the number of stones in the level (i+1).\nExamples:\n>>> makeAPile(3)\n[3, 5, 7]", "instruction": "Write a JavaScript function `const makeAPile = (n)` to solve the following problem:\nGiven a positive integer n, you have to make a pile of n levels of stones.\nThe first level has n stones.\nThe number of stones in the next level is:\n- the next odd number if n is odd.\n- the next even number if n is even.\nReturn the number of stones in each level in a list, where element at index\ni represents the number of stones in the level (i+1).\nExamples:\n>>> makeAPile(3)\n[3, 5, 7]"} +{"task_id": "JavaScript/101", "prompt": "/*\n You will be given a string of words separated by commas or spaces. Your task is\n to split the string into words and return an array of the words.\n \n For example:\n wordsString(\"Hi, my name is John\") == [\"Hi\", \"my\", \"name\", \"is\", \"John\"]\n wordsString(\"One, two, three, four, five, six\") == [\"One\", \"two\", \"three\", \"four\", \"five\", \"six\"]\n */\nconst wordsString = (s) => {\n", "canonical_solution": " let t = ''\n let p = []\n let k = 0\n for (let i = 0; i < s.length; i++) {\n if (s[i] == ' ' || s[i] == ',') {\n if (k == 0) {\n k = 1;\n p.push(t);\n t = '';\n }\n }\n else {\n k = 0;\n t += s[i]\n }\n }\n if (t != '') {\n p.push(t);\n }\n return p\n}\n\n", "test": "const testWordsString = () => {\n console.assert(\n JSON.stringify(wordsString('Hi, my name is John')) ===\n JSON.stringify(['Hi', 'my', 'name', 'is', 'John'])\n )\n console.assert(\n JSON.stringify(wordsString('One, two, three, four, five, six')) ===\n JSON.stringify(['One', 'two', 'three', 'four', 'five', 'six'])\n )\n console.assert(\n JSON.stringify(wordsString('Hi, my name')) ===\n JSON.stringify(['Hi', 'my', 'name'])\n )\n console.assert(\n JSON.stringify(wordsString('One,, two, three, four, five, six,')) ===\n JSON.stringify(['One', 'two', 'three', 'four', 'five', 'six'])\n )\n console.assert(JSON.stringify(wordsString('')) === JSON.stringify([]))\n console.assert(\n JSON.stringify(wordsString('ahmed , gamal')) ===\n JSON.stringify(['ahmed', 'gamal'])\n )\n}\n\ntestWordsString()\n", "declaration": "\nconst wordsString = (s) => {\n", "example_test": "const testWordsString = () => {\n console.assert(\n JSON.stringify(wordsString('Hi, my name is John')) ===\n JSON.stringify(['Hi', 'my', 'name', 'is', 'John'])\n )\n console.assert(\n JSON.stringify(wordsString('One, two, three, four, five, six')) ===\n JSON.stringify(['One', 'two', 'three', 'four', 'five', 'six'])\n )\n}\ntestWordsString()\n", "buggy_solution": " let t = ','\n let p = []\n let k = 0\n for (let i = 0; i < s.length; i++) {\n if (s[i] == ' ' || s[i] == ',') {\n if (k == 0) {\n k = 1;\n p.push(t);\n t = ',';\n }\n }\n else {\n k = 0;\n t += s[i]\n }\n }\n if (t != '') {\n p.push(t);\n }\n return p\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "wordsString", "signature": "const wordsString = (s)", "docstring": "You will be given a string of words separated by commas or spaces. Your task is\nto split the string into words and return an array of the words.\nFor example:\nwordsString(\"Hi, my name is John\") == [\"Hi\", \"my\", \"name\", \"is\", \"John\"]\nwordsString(\"One, two, three, four, five, six\") == [\"One\", \"two\", \"three\", \"four\", \"five\", \"six\"]", "instruction": "Write a JavaScript function `const wordsString = (s)` to solve the following problem:\nYou will be given a string of words separated by commas or spaces. Your task is\nto split the string into words and return an array of the words.\nFor example:\nwordsString(\"Hi, my name is John\") == [\"Hi\", \"my\", \"name\", \"is\", \"John\"]\nwordsString(\"One, two, three, four, five, six\") == [\"One\", \"two\", \"three\", \"four\", \"five\", \"six\"]"} +{"task_id": "JavaScript/102", "prompt": "/*This function takes two positive numbers x and y and returns the\n biggest even integer number that is in the range [x, y] inclusive. If \n there's no such number, then the function should return -1.\n\n For example:\n chooseNum(12, 15) = 14\n chooseNum(13, 12) = -1\n */\nconst chooseNum = (x, y) => {\n", "canonical_solution": " for (let i = y; i >= x; i--) {\n if (i % 2 == 0) {return i }\n }\n return -1\n}\n\n", "test": "const testChooseNum = () => {\n console.assert(chooseNum(12, 15) === 14)\n console.assert(chooseNum(13, 12) === -1)\n console.assert(chooseNum(33, 12354) === 12354)\n console.assert(chooseNum(5234, 5233) === -1)\n console.assert(chooseNum(6, 29) === 28)\n console.assert(chooseNum(27, 10) === -1)\n console.assert(chooseNum(7, 7) === -1)\n console.assert(chooseNum(546, 546) === 546)\n}\n\ntestChooseNum()\n", "declaration": "\nconst chooseNum = (x, y) => {\n", "example_test": "const testChooseNum = () => {\n console.assert(chooseNum(12, 15) === 14)\n console.assert(chooseNum(13, 12) === -1)\n}\ntestChooseNum()\n", "buggy_solution": " for (let i = y; i >= x; i--) {\n if (i % 2 == 0) {return i }\n }\n return x\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "chooseNum", "signature": "const chooseNum = (x, y)", "docstring": "This function takes two positive numbers x and y and returns the\nbiggest even integer number that is in the range [x, y] inclusive. If\nthere's no such number, then the function should return -1.\nFor example:\nchooseNum(12, 15) = 14\nchooseNum(13, 12) = -1", "instruction": "Write a JavaScript function `const chooseNum = (x, y)` to solve the following problem:\nThis function takes two positive numbers x and y and returns the\nbiggest even integer number that is in the range [x, y] inclusive. If\nthere's no such number, then the function should return -1.\nFor example:\nchooseNum(12, 15) = 14\nchooseNum(13, 12) = -1"} +{"task_id": "JavaScript/103", "prompt": "/*You are given two positive integers n and m, and your task is to compute the\n average of the integers from n through m (including n and m). \n Round the answer to the nearest integer and convert that to binary.\n If n is greater than m, return -1.\n Example:\n roundedAvg(1, 5) => \"0b11\"\n roundedAvg(7, 5) => -1\n roundedAvg(10, 20) => \"0b1111\"\n roundedAvg(20, 33) => \"0b11010\"\n */\nconst roundedAvg = (n, m) => {\n", "canonical_solution": " if (n > m) { return -1 }\n let k = (n + m) / 2\n if (k % 1 != 0) { k = (n + m + 1) / 2 }\n return '0b' + k.toString(2)\n}\n\n", "test": "const testRoundedAvg = () => {\n console.assert(roundedAvg(1, 5) === '0b11')\n console.assert(roundedAvg(7, 13) === '0b1010')\n console.assert(roundedAvg(964, 977) === '0b1111001011')\n console.assert(roundedAvg(996, 997) === '0b1111100101')\n console.assert(roundedAvg(560, 851) === '0b1011000010')\n console.assert(roundedAvg(185, 546) === '0b101101110')\n console.assert(roundedAvg(362, 496) === '0b110101101')\n console.assert(roundedAvg(350, 902) === '0b1001110010')\n console.assert(roundedAvg(197, 233) === '0b11010111')\n console.assert(roundedAvg(7, 5) === -1)\n console.assert(roundedAvg(5, 1) === -1)\n console.assert(roundedAvg(5, 5) === '0b101')\n}\n\ntestRoundedAvg()\n", "declaration": "\nconst roundedAvg = (n, m) => {\n", "example_test": "const testRoundedAvg = () => {\n console.assert(roundedAvg(1, 5) === '0b11')\n console.assert(roundedAvg(7, 13) === '0b1010')\n console.assert(roundedAvg(7, 5) === -1)\n console.assert(roundedAvg(10,20) === \"0b1111\")\n console.assert(roundedAvg(20,33) === '0b11011')\n}\ntestRoundedAvg()\n", "buggy_solution": " if (n > m) { return -1 }\n let k = (n + m) / 2\n if (k % 1 != 0) { k = (n + m) / 2 }\n return '0b' + k.toString(2)\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "roundedAvg", "signature": "const roundedAvg = (n, m)", "docstring": "You are given two positive integers n and m, and your task is to compute the\naverage of the integers from n through m (including n and m).\nRound the answer to the nearest integer and convert that to binary.\nIf n is greater than m, return -1.\nExample:\nroundedAvg(1, 5) => \"0b11\"\nroundedAvg(7, 5) => -1\nroundedAvg(10, 20) => \"0b1111\"\nroundedAvg(20, 33) => \"0b11010\"", "instruction": "Write a JavaScript function `const roundedAvg = (n, m)` to solve the following problem:\nYou are given two positive integers n and m, and your task is to compute the\naverage of the integers from n through m (including n and m).\nRound the answer to the nearest integer and convert that to binary.\nIf n is greater than m, return -1.\nExample:\nroundedAvg(1, 5) => \"0b11\"\nroundedAvg(7, 5) => -1\nroundedAvg(10, 20) => \"0b1111\"\nroundedAvg(20, 33) => \"0b11010\""} +{"task_id": "JavaScript/104", "prompt": "/*Given a list of positive integers x. return a sorted list of all \n elements that hasn't any even digit.\n\n Note: Returned list should be sorted in increasing order.\n \n For example:\n >>> uniqueDigits([15, 33, 1422, 1])\n [1, 15, 33]\n >>> uniqueDigits([152, 323, 1422, 10])\n []\n */\nconst uniqueDigits = (x) => {\n", "canonical_solution": " let p = []\n for (let i = 0; i < x.length; i++) {\n let h = x[i]\n let boo = 1\n while (h > 0) {\n let r = h % 10\n if (r % 2 == 0) {\n boo = 0;\n break;\n }\n h = (h - r) / 10\n }\n if (boo) {\n p.push(x[i])\n }\n }\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "test": "const testUniqueDigits = () => {\n console.assert(\n JSON.stringify(uniqueDigits([15, 33, 1422, 1])) ===\n JSON.stringify([1, 15, 33])\n )\n console.assert(\n JSON.stringify(uniqueDigits([152, 323, 1422, 10])) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(uniqueDigits([12345, 2033, 111, 151])) ===\n JSON.stringify([111, 151])\n )\n console.assert(\n JSON.stringify(uniqueDigits([135, 103, 31])) === JSON.stringify([31, 135])\n )\n}\n\ntestUniqueDigits()\n", "declaration": "\nconst uniqueDigits = (x) => {\n", "example_test": "const testUniqueDigits = () => {\n console.assert(\n JSON.stringify(uniqueDigits([15, 33, 1422, 1])) ===\n JSON.stringify([1, 15, 33])\n )\n console.assert(\n JSON.stringify(uniqueDigits([152, 323, 1422, 10])) === JSON.stringify([])\n )\n}\ntestUniqueDigits()\n", "buggy_solution": " let p = []\n for (let i = 0; i < x.length; i++) {\n let h = x[i]\n let boo = 1\n while (h > 0) {\n let r = h % 10\n if (r % 2 == 0) {\n boo = 0;\n break;\n }\n h = (h - r) / 10\n }\n if (boo) {\n p.push(x[i]);\n p.push(h);\n }\n }\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "uniqueDigits", "signature": "const uniqueDigits = (x)", "docstring": "Given a list of positive integers x. return a sorted list of all\nelements that hasn't any even digit.\nNote: Returned list should be sorted in increasing order.\nFor example:\n>>> uniqueDigits([15, 33, 1422, 1])\n[1, 15, 33]\n>>> uniqueDigits([152, 323, 1422, 10])\n[]", "instruction": "Write a JavaScript function `const uniqueDigits = (x)` to solve the following problem:\nGiven a list of positive integers x. return a sorted list of all\nelements that hasn't any even digit.\nNote: Returned list should be sorted in increasing order.\nFor example:\n>>> uniqueDigits([15, 33, 1422, 1])\n[1, 15, 33]\n>>> uniqueDigits([152, 323, 1422, 10])\n[]"} +{"task_id": "JavaScript/105", "prompt": "/*\n Given an array of integers, sort the integers that are between 1 and 9 inclusive,\n reverse the resulting array, and then replace each digit by its corresponding name from\n \"One\", \"Two\", \"Three\", \"Four\", \"Five\", \"Six\", \"Seven\", \"Eight\", \"Nine\".\n\n For example:\n arr = [2, 1, 1, 4, 5, 8, 2, 3] \n -> sort arr -> [1, 1, 2, 2, 3, 4, 5, 8] \n -> reverse arr -> [8, 5, 4, 3, 2, 2, 1, 1]\n return [\"Eight\", \"Five\", \"Four\", \"Three\", \"Two\", \"Two\", \"One\", \"One\"]\n \n If the array is empty, return an empty array:\n arr = []\n return []\n \n If the array has any strange number ignore it:\n arr = [1, -1 , 55] \n -> sort arr -> [-1, 1, 55]\n -> reverse arr -> [55, 1, -1]\n return = ['One']\n */\nconst byLength = (arr) => {\n", "canonical_solution": " p = []\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] > 0 && arr[i] < 10) { p.push(arr[i]) }\n }\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] > p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n let l = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine']\n let t = []\n for (let j = 0; j < p.length; j++) {\n t.push(l[p[j]-1])\n }\n return t\n}\n\n", "test": "const testByLength = () => {\n console.assert(\n JSON.stringify(byLength([2, 1, 1, 4, 5, 8, 2, 3])) ===\n JSON.stringify([\n 'Eight',\n 'Five',\n 'Four',\n 'Three',\n 'Two',\n 'Two',\n 'One',\n 'One',\n ])\n )\n console.assert(JSON.stringify(byLength([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(byLength([1, -1, 55])) === JSON.stringify(['One'])\n )\n console.assert(\n JSON.stringify(byLength([1, -1, 3, 2])) ===\n JSON.stringify(['Three', 'Two', 'One'])\n )\n console.assert(\n JSON.stringify(byLength([9, 4, 8])) ===\n JSON.stringify(['Nine', 'Eight', 'Four'])\n )\n}\n\ntestByLength()\n", "declaration": "\nconst byLength = (arr) => {\n", "example_test": "const testByLength = () => {\n console.assert(\n JSON.stringify(byLength([2, 1, 1, 4, 5, 8, 2, 3])) ===\n JSON.stringify([\n 'Eight',\n 'Five',\n 'Four',\n 'Three',\n 'Two',\n 'Two',\n 'One',\n 'One',\n ])\n )\n console.assert(JSON.stringify(byLength([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(byLength([1, -1, 55])) === JSON.stringify(['One'])\n )\n}\ntestByLength()\n", "buggy_solution": " p = []\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] > 0 && arr[i] < 10) { p.push(arr[i]) }\n }\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] > p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[ind] = tmp\n }\n }\n let l = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine']\n let t = []\n for (let j = 0; j < p.length; j++) {\n t.push(l[p[j]-1])\n }\n return t\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "byLength", "signature": "const byLength = (arr)", "docstring": "Given an array of integers, sort the integers that are between 1 and 9 inclusive,\nreverse the resulting array, and then replace each digit by its corresponding name from\n\"One\", \"Two\", \"Three\", \"Four\", \"Five\", \"Six\", \"Seven\", \"Eight\", \"Nine\".\nFor example:\narr = [2, 1, 1, 4, 5, 8, 2, 3]\n-> sort arr -> [1, 1, 2, 2, 3, 4, 5, 8]\n-> reverse arr -> [8, 5, 4, 3, 2, 2, 1, 1]\nreturn [\"Eight\", \"Five\", \"Four\", \"Three\", \"Two\", \"Two\", \"One\", \"One\"]\nIf the array is empty, return an empty array:\narr = []\nreturn []\nIf the array has any strange number ignore it:\narr = [1, -1 , 55]\n-> sort arr -> [-1, 1, 55]\n-> reverse arr -> [55, 1, -1]\nreturn = ['One']", "instruction": "Write a JavaScript function `const byLength = (arr)` to solve the following problem:\nGiven an array of integers, sort the integers that are between 1 and 9 inclusive,\nreverse the resulting array, and then replace each digit by its corresponding name from\n\"One\", \"Two\", \"Three\", \"Four\", \"Five\", \"Six\", \"Seven\", \"Eight\", \"Nine\".\nFor example:\narr = [2, 1, 1, 4, 5, 8, 2, 3]\n-> sort arr -> [1, 1, 2, 2, 3, 4, 5, 8]\n-> reverse arr -> [8, 5, 4, 3, 2, 2, 1, 1]\nreturn [\"Eight\", \"Five\", \"Four\", \"Three\", \"Two\", \"Two\", \"One\", \"One\"]\nIf the array is empty, return an empty array:\narr = []\nreturn []\nIf the array has any strange number ignore it:\narr = [1, -1 , 55]\n-> sort arr -> [-1, 1, 55]\n-> reverse arr -> [55, 1, -1]\nreturn = ['One']"} +{"task_id": "JavaScript/106", "prompt": "/* Implement the function f that takes n as a parameter,\n and returns a list of size n, such that the value of the element at index i is the factorial of i if i is even\n or the sum of numbers from 1 to i otherwise.\n i starts from 1.\n the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).\n Example:\n f(5) == [1, 2, 6, 24, 15]\n */\nconst f = (n) => {\n", "canonical_solution": " let f = 1\n let p = 0\n let k = []\n for (let i = 1; i <= n; i++) {\n p += i;\n f *= i;\n if (i % 2 == 0) { k.push(f) }\n else { k.push(p) }\n }\n return k\n}\n\n", "test": "const testF = () => {\n console.assert(JSON.stringify(f(5)) === JSON.stringify([1, 2, 6, 24, 15]))\n console.assert(\n JSON.stringify(f(7)) === JSON.stringify([1, 2, 6, 24, 15, 720, 28])\n )\n console.assert(JSON.stringify(f(1)) === JSON.stringify([1]))\n console.assert(JSON.stringify(f(3)) === JSON.stringify([1, 2, 6]))\n}\n\ntestF()\n", "declaration": "\nconst f = (n) => {\n", "example_test": "const testF = () => {\n console.assert(JSON.stringify(f(5)) === JSON.stringify([1, 2, 6, 24, 15]))\n}\ntestF()\n", "buggy_solution": " let f = 1\n let p = 0\n let k = []\n for (let i = 1; i <= n; i++) {\n p += i;\n f *= i;\n if (f % 2 == 0) { k.push(f) }\n else { k.push(p) }\n }\n return k\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "f", "signature": "const f = (n)", "docstring": "Implement the function f that takes n as a parameter,\nand returns a list of size n, such that the value of the element at index i is the factorial of i if i is even\nor the sum of numbers from 1 to i otherwise.\ni starts from 1.\nthe factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).\nExample:\nf(5) == [1, 2, 6, 24, 15]", "instruction": "Write a JavaScript function `const f = (n)` to solve the following problem:\nImplement the function f that takes n as a parameter,\nand returns a list of size n, such that the value of the element at index i is the factorial of i if i is even\nor the sum of numbers from 1 to i otherwise.\ni starts from 1.\nthe factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).\nExample:\nf(5) == [1, 2, 6, 24, 15]"} +{"task_id": "JavaScript/107", "prompt": "/*\n Given a positive integer n, return a tuple that has the number of even and odd\n integer palindromes that fall within the range(1, n), inclusive.\n\n Example 1:\n\n Input: 3\n Output: (1, 2)\n Explanation:\n Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.\n\n Example 2:\n\n Input: 12\n Output: (4, 6)\n Explanation:\n Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.\n\n Note:\n 1. 1 <= n <= 10^3\n 2. returned tuple has the number of even and odd integer palindromes respectively.\n */\nconst evenOddPalindrome = (n) => {\n", "canonical_solution": " let e = 0\n let o = 0\n for (let i = 1; i <= n; i++) {\n let k = i.toString()\n let p = 1\n for (let j = 0; j < k.length; j++) {\n if (k[j] != k[k.length - j - 1]) {\n p = 0;\n break;\n }\n }\n if (p == 1) {\n if (k % 2 == 0) { e++ }\n else { o++ }\n }\n }\n return (e, o)\n}\n\n", "test": "const testEvenOddPalindrome = () => {\n console.assert(\n JSON.stringify(evenOddPalindrome(123)) === JSON.stringify((8, 13))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(12)) === JSON.stringify((4, 6))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(3)) === JSON.stringify((1, 2))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(63)) === JSON.stringify((6, 8))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(25)) === JSON.stringify((5, 6))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(19)) === JSON.stringify((4, 6))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(9)) === JSON.stringify((4, 5))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(1)) === JSON.stringify((0, 1))\n )\n}\n\ntestEvenOddPalindrome()\n", "declaration": "\nconst evenOddPalindrome = (n) => {\n", "example_test": "const testEvenOddPalindrome = () => {\n console.assert(\n JSON.stringify(evenOddPalindrome(12)) === JSON.stringify((4, 6))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(3)) === JSON.stringify((1, 2))\n )\n}\ntestEvenOddPalindrome()\n", "buggy_solution": " let e = 0\n let o = 0\n for (let i = 1; i <= n; i++) {\n let k = i.toString()\n let p = 1\n for (let j = 0; j < k.length; j++) {\n if (k[j] != k[k.length - j - 1]) {\n p = 0;\n break;\n }\n }\n if (p == 1) {\n if (k % 2 == 1) { e++ }\n else { o++ }\n }\n }\n return (e, o)\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "evenOddPalindrome", "signature": "const evenOddPalindrome = (n)", "docstring": "Given a positive integer n, return a tuple that has the number of even and odd\ninteger palindromes that fall within the range(1, n), inclusive.\nExample 1:\nInput: 3\nOutput: (1, 2)\nExplanation:\nInteger palindrome are 1, 2, 3. one of them is even, and two of them are odd.\nExample 2:\nInput: 12\nOutput: (4, 6)\nExplanation:\nInteger palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.\nNote:\n1. 1 <= n <= 10^3\n2. returned tuple has the number of even and odd integer palindromes respectively.", "instruction": "Write a JavaScript function `const evenOddPalindrome = (n)` to solve the following problem:\nGiven a positive integer n, return a tuple that has the number of even and odd\ninteger palindromes that fall within the range(1, n), inclusive.\nExample 1:\nInput: 3\nOutput: (1, 2)\nExplanation:\nInteger palindrome are 1, 2, 3. one of them is even, and two of them are odd.\nExample 2:\nInput: 12\nOutput: (4, 6)\nExplanation:\nInteger palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.\nNote:\n1. 1 <= n <= 10^3\n2. returned tuple has the number of even and odd integer palindromes respectively."} +{"task_id": "JavaScript/108", "prompt": "/*\n Write a function countNums which takes an array of integers and returns\n the number of elements which has a sum of digits > 0.\n If a number is negative, then its first signed digit will be negative:\n e.g. -123 has signed digits -1, 2, and 3.\n >>> countNums([]) == 0\n >>> countNums([-1, 11, -11]) == 1\n >>> countNums([1, 1, 2]) == 3\n */\nconst countNums = (arr) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < arr.length; i++) {\n let h = arr[i]\n if (h > 0) {\n p++;\n continue;\n }\n let k = 0\n h = -h\n while (h >= 10) {\n k += h % 10;\n h = (h - h % 10) / 10;\n }\n k -= h;\n if (k > 0) { p++ }\n }\n return p\n}\n\n", "test": "const testCountNums = () => {\n console.assert(countNums([]) === 0)\n console.assert(countNums([-1, -2, 0]) === 0)\n console.assert(countNums([1, 1, 2, -2, 3, 4, 5]) === 6)\n console.assert(countNums([1, 6, 9, -6, 0, 1, 5]) === 5)\n console.assert(countNums([1, 100, 98, -7, 1, -1]) === 4)\n console.assert(countNums([12, 23, 34, -45, -56, 0]) === 5)\n console.assert(countNums([-0, 1 ** 0]) === 1)\n console.assert(countNums([1]) === 1)\n}\n\ntestCountNums()\n", "declaration": "\nconst countNums = (arr) => {\n", "example_test": "const testCountNums = () => {\n console.assert(countNums([]) === 0)\n console.assert(countNums([-1, 11, -11]) === 1)\n console.assert(countNums([1, 1, 2]) === 3)\n}\ntestCountNums()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < arr.length; i++) {\n let h = arr[i]\n if (h > 0) {\n p++;\n continue;\n }\n let k = 0\n h = -h\n while (h >= 10) {\n k += h % 10 * -1;\n h = (h - h % 10) / 10;\n }\n k -= h;\n if (k > 0) { p++ }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "countNums", "signature": "const countNums = (arr)", "docstring": "Write a function countNums which takes an array of integers and returns\nthe number of elements which has a sum of digits > 0.\nIf a number is negative, then its first signed digit will be negative:\ne.g. -123 has signed digits -1, 2, and 3.\n>>> countNums([]) == 0\n>>> countNums([-1, 11, -11]) == 1\n>>> countNums([1, 1, 2]) == 3", "instruction": "Write a JavaScript function `const countNums = (arr)` to solve the following problem:\nWrite a function countNums which takes an array of integers and returns\nthe number of elements which has a sum of digits > 0.\nIf a number is negative, then its first signed digit will be negative:\ne.g. -123 has signed digits -1, 2, and 3.\n>>> countNums([]) == 0\n>>> countNums([-1, 11, -11]) == 1\n>>> countNums([1, 1, 2]) == 3"} +{"task_id": "JavaScript/109", "prompt": "/*We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The\n numbers in the array will be randomly ordered. Your task is to determine if\n it is possible to get an array sorted in non-decreasing order by performing \n the following operation on the given array:\n You are allowed to perform right shift operation any number of times.\n \n One right shift operation means shifting all elements of the array by one\n position in the right direction. The last element of the array will be moved to\n the starting position in the array i.e. 0th index. \n\n If it is possible to obtain the sorted array by performing the above operation\n then return true else return false.\n If the given array is empty then return true.\n\n Note: The given list is guaranteed to have unique elements.\n\n For Example:\n \n moveOneBall([3, 4, 5, 1, 2])==>true\n Explanation: By performin 2 right shift operations, non-decreasing order can\n be achieved for the given array.\n moveOneBall([3, 5, 4, 1, 2])==>false\n Explanation:It is not possible to get non-decreasing order for the given\n array by performing any number of right shift operations.\n \n */\nconst moveOneBall = (arr) => {\n", "canonical_solution": " if (arr.length == 0) { return true }\n let k = 0\n let len = arr.length\n for (let i = 0; i < len; i++) {\n let t = 1;\n for (let j = 1; j < len; j++) {\n if (arr[j] < arr[j - 1]) {\n t = 0;\n break;\n }\n }\n if (t == 1) {\n k = 1;\n break;\n }\n arr.push(arr[0]);\n arr.shift()\n }\n if (k == 1) { return true }\n return false\n}\n\n", "test": "const testMoveOneBall = () => {\n console.assert(moveOneBall([3, 4, 5, 1, 2]) === true)\n console.assert(moveOneBall([3, 5, 10, 1, 2]) === true)\n console.assert(moveOneBall([4, 3, 1, 2]) === false)\n console.assert(moveOneBall([3, 5, 4, 1, 2]) === false)\n console.assert(moveOneBall([]) === true)\n}\n\ntestMoveOneBall()\n", "declaration": "\nconst moveOneBall = (arr) => {\n", "example_test": "const testMoveOneBall = () => {\n console.assert(moveOneBall([3, 4, 5, 1, 2]) === true)\n console.assert(moveOneBall([3, 5, 4, 1, 2]) === false)\n}\ntestMoveOneBall()\n", "buggy_solution": " if (arr.length == 0) { return true }\n let k = 0\n let len = arr.length\n for (let i = 0; i < len; i++) {\n let t = 1;\n for (let j = 1; j < len; j++) {\n if (arr[j] < arr[j - 1]) {\n t = 0;\n break;\n }\n }\n if (t == 1) {\n k = 1;\n break;\n }\n arr.push(arr[j]);\n arr.shift()\n }\n if (k == 1) { return true }\n return false\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "moveOneBall", "signature": "const moveOneBall = (arr)", "docstring": "We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The\nnumbers in the array will be randomly ordered. Your task is to determine if\nit is possible to get an array sorted in non-decreasing order by performing\nthe following operation on the given array:\nYou are allowed to perform right shift operation any number of times.\nOne right shift operation means shifting all elements of the array by one\nposition in the right direction. The last element of the array will be moved to\nthe starting position in the array i.e. 0th index.\nIf it is possible to obtain the sorted array by performing the above operation\nthen return true else return false.\nIf the given array is empty then return true.\nNote: The given list is guaranteed to have unique elements.\nFor Example:\nmoveOneBall([3, 4, 5, 1, 2])==>true\nExplanation: By performin 2 right shift operations, non-decreasing order can\nbe achieved for the given array.\nmoveOneBall([3, 5, 4, 1, 2])==>false\nExplanation:It is not possible to get non-decreasing order for the given\narray by performing any number of right shift operations.", "instruction": "Write a JavaScript function `const moveOneBall = (arr)` to solve the following problem:\nWe have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The\nnumbers in the array will be randomly ordered. Your task is to determine if\nit is possible to get an array sorted in non-decreasing order by performing\nthe following operation on the given array:\nYou are allowed to perform right shift operation any number of times.\nOne right shift operation means shifting all elements of the array by one\nposition in the right direction. The last element of the array will be moved to\nthe starting position in the array i.e. 0th index.\nIf it is possible to obtain the sorted array by performing the above operation\nthen return true else return false.\nIf the given array is empty then return true.\nNote: The given list is guaranteed to have unique elements.\nFor Example:\nmoveOneBall([3, 4, 5, 1, 2])==>true\nExplanation: By performin 2 right shift operations, non-decreasing order can\nbe achieved for the given array.\nmoveOneBall([3, 5, 4, 1, 2])==>false\nExplanation:It is not possible to get non-decreasing order for the given\narray by performing any number of right shift operations."} +{"task_id": "JavaScript/110", "prompt": "/*In this problem, you will implement a function that takes two lists of numbers,\n and determines whether it is possible to perform an exchange of elements\n between them to make lst1 a list of only even numbers.\n There is no limit on the number of exchanged elements between lst1 and lst2.\n If it is possible to exchange elements between the lst1 and lst2 to make\n all the elements of lst1 to be even, return \"YES\".\n Otherwise, return \"NO\".\n For example:\n exchange([1, 2, 3, 4], [1, 2, 3, 4]) => \"YES\"\n exchange([1, 2, 3, 4], [1, 5, 3, 4]) => \"NO\"\n It is assumed that the input lists will be non-empty.\n */\nconst exchange = (lst1, lst2) => {\n", "canonical_solution": " let k = lst1.length\n let t = 0\n for (let i = 0; i < lst1.length; i++) {\n if (lst1[i] % 2 == 0) { t++ }\n }\n for (let i = 0; i < lst2.length; i++) {\n if (lst2[i] % 2 == 0) { t++ }\n }\n if (t >= k) { return 'YES' }\n return 'NO'\n}\n\n", "test": "const testExchange = () => {\n console.assert(exchange([1, 2, 3, 4], [1, 2, 3, 4]) === 'YES')\n console.assert(exchange([1, 2, 3, 4], [1, 5, 3, 4]) === 'NO')\n console.assert(exchange([1, 2, 3, 4], [2, 1, 4, 3]) === 'YES')\n console.assert(exchange([5, 7, 3], [2, 6, 4]) === 'YES')\n console.assert(exchange([5, 7, 3], [2, 6, 3]) === 'NO')\n console.assert(exchange([3, 2, 6, 1, 8, 9], [3, 5, 5, 1, 1, 1]) === 'NO')\n console.assert(exchange([100, 200], [200, 200]) === 'YES')\n}\n\ntestExchange()\n", "declaration": "\nconst exchange = (lst1, lst2) => {\n", "example_test": "const testExchange = () => {\n console.assert(exchange([1, 2, 3, 4], [1, 2, 3, 4]) === 'YES')\n console.assert(exchange([1, 2, 3, 4], [1, 5, 3, 4]) === 'NO')\n}\ntestExchange()\n", "buggy_solution": " let k = lst1.length\n let t = 0\n for (let i = 0; i < lst1.length; i++) {\n if (lst1[i] % 2 == 0) { t++ }\n }\n for (let i = 0; i < lst2.length; i++) {\n if (lst2[i] % 2 == 0) { t++ }\n }\n if (k >= t) { return 'YES' }\n return 'NO'\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "exchange", "signature": "const exchange = (lst1, lst2)", "docstring": "In this problem, you will implement a function that takes two lists of numbers,\nand determines whether it is possible to perform an exchange of elements\nbetween them to make lst1 a list of only even numbers.\nThere is no limit on the number of exchanged elements between lst1 and lst2.\nIf it is possible to exchange elements between the lst1 and lst2 to make\nall the elements of lst1 to be even, return \"YES\".\nOtherwise, return \"NO\".\nFor example:\nexchange([1, 2, 3, 4], [1, 2, 3, 4]) => \"YES\"\nexchange([1, 2, 3, 4], [1, 5, 3, 4]) => \"NO\"\nIt is assumed that the input lists will be non-empty.", "instruction": "Write a JavaScript function `const exchange = (lst1, lst2)` to solve the following problem:\nIn this problem, you will implement a function that takes two lists of numbers,\nand determines whether it is possible to perform an exchange of elements\nbetween them to make lst1 a list of only even numbers.\nThere is no limit on the number of exchanged elements between lst1 and lst2.\nIf it is possible to exchange elements between the lst1 and lst2 to make\nall the elements of lst1 to be even, return \"YES\".\nOtherwise, return \"NO\".\nFor example:\nexchange([1, 2, 3, 4], [1, 2, 3, 4]) => \"YES\"\nexchange([1, 2, 3, 4], [1, 5, 3, 4]) => \"NO\"\nIt is assumed that the input lists will be non-empty."} +{"task_id": "JavaScript/111", "prompt": "/*Given a string representing a space separated lowercase letters, return a dictionary\n of the letter with the most repetition and containing the corresponding count.\n If several letters have the same occurrence, return all of them.\n \n Example:\n histogram('a b c') == {'a': 1, 'b': 1, 'c': 1}\n histogram('a b b a') == {'a': 2, 'b': 2}\n histogram('a b c a b') == {'a': 2, 'b': 2}\n histogram('b b b b a') == {'b': 4}\n histogram('') == {}\n\n */\nconst histogram = (test) => {\n", "canonical_solution": " let d = {}\n let t = test.split(/\\s/)\n if (test == '') { t = [] }\n for (m in t) {\n if (t[m] in d) {\n d[t[m]]++\n }\n else {\n d[t[m]] = 1\n }\n }\n s = Object.keys(d).sort(function (a, b) { return - d[a] + d[b]; });\n if (s.length == 0) { return {} }\n let g = d[s[0]]\n let l = {}\n for (let ss=0; ss {\n console.assert(\n JSON.stringify(histogram('a b b a')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c a b')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c d g')) ===\n JSON.stringify({ a: 1, b: 1, c: 1, d: 1, g: 1 })\n )\n console.assert(\n JSON.stringify(histogram('r t g')) === JSON.stringify({ r: 1, t: 1, g: 1 })\n )\n console.assert(\n JSON.stringify(histogram('b b b b a')) === JSON.stringify({ b: 4 })\n )\n console.assert(\n JSON.stringify(histogram('r t g')) === JSON.stringify({ r: 1, t: 1, g: 1 })\n )\n console.assert(JSON.stringify(histogram('')) === JSON.stringify({}))\n console.assert(JSON.stringify(histogram('a')) === JSON.stringify({ a: 1 }))\n}\n\ntestHistogram()\n", "declaration": "\nconst histogram = (test) => {\n", "example_test": "const testHistogram = () => {\n console.assert(\n JSON.stringify(histogram('a b b a')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c a b')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c d g')) ===\n JSON.stringify({ a: 1, b: 1, c: 1, d: 1, g: 1 })\n )\n console.assert(\n JSON.stringify(histogram('a b c')) === JSON.stringify({ a: 1, b: 1, c: 1 })\n )\n console.assert(\n JSON.stringify(histogram('b b b b a')) === JSON.stringify({ b: 4 })\n )\n console.assert(JSON.stringify(histogram('')) === JSON.stringify({}))\n}\ntestHistogram()\n", "buggy_solution": " let d = {}\n let t = test.split(/\\s/)\n if (test == '') { t = [] }\n for (m in t) {\n if (t[m] in d) {\n d[t[m]]++\n }\n else {\n d[t[m]] = 1\n }\n }\n s = Object.keys(d).sort(function (a, b) { return - d[a] + d[b]; });\n if (s.length == 0) { return {} }\n let g = d[s[0]]\n let l = {}\n for (let ss=1; ss {\n", "canonical_solution": " let t = ''\n for (let i = 0; i < s.length; i++) {\n let y = 1\n for (let j = 0; j < c.length; j++) {\n if (s[i] == c[j]) {\n y = 0\n }\n }\n if (y == 1) {\n t += s[i]\n }\n }\n let isPalindrome = true\n for (let i = 0; i < Math.floor(t.length / 2); i++) {\n if (t[i] != t[t.length - i - 1]) {\n isPalindrome = false\n break\n }\n }\n return [t, isPalindrome];\n}\n\n", "test": "const testReverseDelete = () => {\n console.assert(JSON.stringify(reverseDelete('abcde', 'ae')) ===\n JSON.stringify(['bcd', false]))\n console.assert(JSON.stringify(reverseDelete('abcdef', 'b')) ===\n JSON.stringify(['acdef', false]))\n console.assert(JSON.stringify(reverseDelete('abcdedcba', 'ab')) ===\n JSON.stringify(['cdedc', true]))\n console.assert(JSON.stringify(reverseDelete('dwik', 'w')) ===\n JSON.stringify(['dik', false]))\n console.assert(JSON.stringify(reverseDelete('a', 'a')) ===\n JSON.stringify(['', true]))\n console.assert(JSON.stringify(reverseDelete('abcdedcba', '')) ===\n JSON.stringify(['abcdedcba', true]))\n console.assert(JSON.stringify(reverseDelete('abcdedcba', 'v')) ===\n JSON.stringify(['abcdedcba', true]))\n console.assert(JSON.stringify(reverseDelete('vabba', 'v')) ===\n JSON.stringify(['abba', true]))\n console.assert(JSON.stringify(reverseDelete('mamma', 'mia')) ===\n JSON.stringify(['', true]))\n}\n\ntestReverseDelete()\n", "declaration": "\nconst reverseDelete = (s, c) => {\n", "example_test": "const testReverseDelete = () => {\n console.assert(JSON.stringify(reverseDelete('abcde', 'ae'))) ===\n JSON.stringify(['bcd', false])\n console.assert(JSON.stringify(reverseDelete('abcdef', 'b'))) ===\n JSON.stringify(['acdef', false])\n console.assert(JSON.stringify(reverseDelete('abcdedcba', 'ab'))) ===\n JSON.stringify(['cdedc', true])\n}\ntestReverseDelete()\n", "buggy_solution": " let t = ''\n for (let i = 0; i < s.length; i++) {\n let y = 1\n for (let j = 0; j < c.length; j++) {\n if (s[i] == c[j]) {\n y = 0\n }\n }\n if (y == 1) {\n t += s[i]\n }\n }\n let isPalindrome = false\n for (let i = 0; i < Math.floor(t.length / 2); i++) {\n if (t[i] != t[t.length - i - 1]) {\n isPalindrome = true\n break\n }\n }\n return [t, isPalindrome];\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "reverseDelete", "signature": "const reverseDelete = (s, c)", "docstring": "Task\nWe are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c\nthen check if the result string is palindrome.\nA string is called palindrome if it reads the same backward as forward.\nYou should return a tuple containing the result string and true/false for the check.\nExample\nFor s = \"abcde\", c = \"ae\", the result should be ('bcd',false)\nFor s = \"abcdef\", c = \"b\" the result should be ('acdef',false)\nFor s = \"abcdedcba\", c = \"ab\", the result should be ('cdedc',true)", "instruction": "Write a JavaScript function `const reverseDelete = (s, c)` to solve the following problem:\nTask\nWe are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c\nthen check if the result string is palindrome.\nA string is called palindrome if it reads the same backward as forward.\nYou should return a tuple containing the result string and true/false for the check.\nExample\nFor s = \"abcde\", c = \"ae\", the result should be ('bcd',false)\nFor s = \"abcdef\", c = \"b\" the result should be ('acdef',false)\nFor s = \"abcdedcba\", c = \"ab\", the result should be ('cdedc',true)"} +{"task_id": "JavaScript/113", "prompt": "/*Given a list of strings, where each string consists of only digits, return a list.\n Each element i of the output should be \"the number of odd elements in the\n string i of the input.\" where all the i's should be replaced by the number\n of odd digits in the i'th string of the input.\n\n >>> oddCount(['1234567'])\n [\"the number of odd elements 4n the str4ng 4 of the 4nput.\"]\n >>> oddCount(['3',\"11111111\"])\n [\"the number of odd elements 1n the str1ng 1 of the 1nput.\",\n \"the number of odd elements 8n the str8ng 8 of the 8nput.\"]\n */\nconst oddCount = (lst) => {\n", "canonical_solution": " let d = []\n for (let i = 0; i < lst.length; i++) {\n let p = 0;\n let h = lst[i].length\n for (let j = 0; j < h; j++) {\n if (lst[i][j].charCodeAt() % 2 == 1) { p++ }\n }\n p = p.toString()\n d.push('the number of odd elements ' + p + 'n the str' + p + 'ng ' + p + ' of the ' + p + 'nput.')\n }\n return d\n}\n\n", "test": "const testOddCount = () => {\n console.assert(\n JSON.stringify(oddCount(['1234567'])) ===\n JSON.stringify([\n 'the number of odd elements 4n the str4ng 4 of the 4nput.',\n ])\n )\n console.assert(JSON.stringify(\n oddCount(['3', '11111111'])) ===\n JSON.stringify([\n 'the number of odd elements 1n the str1ng 1 of the 1nput.',\n 'the number of odd elements 8n the str8ng 8 of the 8nput.',\n ])\n )\n console.assert(\n JSON.stringify(oddCount(['271', '137', '314'])) ===\n JSON.stringify([\n 'the number of odd elements 2n the str2ng 2 of the 2nput.',\n 'the number of odd elements 3n the str3ng 3 of the 3nput.',\n 'the number of odd elements 2n the str2ng 2 of the 2nput.',\n ])\n )\n}\n\ntestOddCount()\n", "declaration": "\nconst oddCount = (lst) => {\n", "example_test": "const testOddCount = () => {\n console.assert(\n JSON.stringify(oddCount(['1234567'])) ===\n JSON.stringify([\n 'the number of odd elements 4n the str4ng 4 of the 4nput.',\n ])\n )\n console.assert(JSON.stringify(\n oddCount(['3', '11111111'])) ===\n JSON.stringify([\n 'the number of odd elements 1n the str1ng 1 of the 1nput.',\n 'the number of odd elements 8n the str8ng 8 of the 8nput.',\n ])\n )\n}\ntestOddCount()\n", "buggy_solution": " let d = []\n for (let i = 0; i < lst.length; i++) {\n let p = 0;\n let h = lst[i].length\n for (let j = 0; j < h; j++) {\n if (lst[i][j].charCodeAt() % 2 == 1) { p++ }\n }\n p = p.toString()\n d.push('the number of odd elements ' + p + 'n the str' + p + 'ng ' + p + ' of ' p + ' the ' + p + 'nput.')\n }\n return d\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "oddCount", "signature": "const oddCount = (lst)", "docstring": "Given a list of strings, where each string consists of only digits, return a list.\nEach element i of the output should be \"the number of odd elements in the\nstring i of the input.\" where all the i's should be replaced by the number\nof odd digits in the i'th string of the input.\n>>> oddCount(['1234567'])\n[\"the number of odd elements 4n the str4ng 4 of the 4nput.\"]\n>>> oddCount(['3',\"11111111\"])\n[\"the number of odd elements 1n the str1ng 1 of the 1nput.\",\n\"the number of odd elements 8n the str8ng 8 of the 8nput.\"]", "instruction": "Write a JavaScript function `const oddCount = (lst)` to solve the following problem:\nGiven a list of strings, where each string consists of only digits, return a list.\nEach element i of the output should be \"the number of odd elements in the\nstring i of the input.\" where all the i's should be replaced by the number\nof odd digits in the i'th string of the input.\n>>> oddCount(['1234567'])\n[\"the number of odd elements 4n the str4ng 4 of the 4nput.\"]\n>>> oddCount(['3',\"11111111\"])\n[\"the number of odd elements 1n the str1ng 1 of the 1nput.\",\n\"the number of odd elements 8n the str8ng 8 of the 8nput.\"]"} +{"task_id": "JavaScript/114", "prompt": "/*\n Given an array of integers nums, find the minimum sum of any non-empty sub-array\n of nums.\n Example\n minSubArraySum([2, 3, 4, 1, 2, 4]) == 1\n minSubArraySum([-1, -2, -3]) == -6\n */\nconst minSubArraySum = (nums) => {\n", "canonical_solution": " let min = nums[0]\n for (let i = 0; i < nums.length; i++) {\n for (let j = i + 1; j <= nums.length; j++) {\n let s = 0;\n for (let k = i; k < j; k++) {\n s += nums[k]\n }\n if (s < min) { min = s }\n }\n }\n return min\n}\n\n", "test": "const testMinSubArraySum = () => {\n console.assert(minSubArraySum([2, 3, 4, 1, 2, 4]) === 1)\n console.assert(minSubArraySum([-1, -2, -3]) === -6)\n console.assert(minSubArraySum([-1, -2, -3, 2, -10]) === -14)\n console.assert(minSubArraySum([-9999999999999999]) === -9999999999999999)\n console.assert(minSubArraySum([0, 10, 20, 1000000]) === 0)\n console.assert(minSubArraySum([-1, -2, -3, 10, -5]) === -6)\n console.assert(minSubArraySum([100, -1, -2, -3, 10, -5]) === -6)\n console.assert(minSubArraySum([10, 11, 13, 8, 3, 4]) === 3)\n console.assert(minSubArraySum([100, -33, 32, -1, 0, -2]) === -33)\n console.assert(minSubArraySum([-10]) === -10)\n console.assert(minSubArraySum([7]) === 7)\n console.assert(minSubArraySum([1, -1]) === -1)\n}\n\ntestMinSubArraySum()\n", "declaration": "\nconst minSubArraySum = (nums) => {\n", "example_test": "const testMinSubArraySum = () => {\n console.assert(minSubArraySum([2, 3, 4, 1, 2, 4]) === 1)\n console.assert(minSubArraySum([-1, -2, -3]) === -6)\n}\ntestMinSubArraySum()\n", "buggy_solution": " let min = Math.min(nums)\n for (let i = 0; i < nums.length; i++) {\n for (let j = i + 1; j <= nums.length; j++) {\n let s = 0;\n for (let k = i; k < j; k++) {\n s += nums[k]\n }\n if (s < min) { min = s }\n }\n }\n return min\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "minSubarraySum", "signature": "const minSubArraySum = (nums)", "docstring": "Given an array of integers nums, find the minimum sum of any non-empty sub-array\nof nums.\nExample\nminSubArraySum([2, 3, 4, 1, 2, 4]) == 1\nminSubArraySum([-1, -2, -3]) == -6", "instruction": "Write a JavaScript function `const minSubArraySum = (nums)` to solve the following problem:\nGiven an array of integers nums, find the minimum sum of any non-empty sub-array\nof nums.\nExample\nminSubArraySum([2, 3, 4, 1, 2, 4]) == 1\nminSubArraySum([-1, -2, -3]) == -6"} +{"task_id": "JavaScript/115", "prompt": "/*\n You are given a rectangular grid of wells. Each row represents a single well,\n and each 1 in a row represents a single unit of water.\n Each well has a corresponding bucket that can be used to extract water from it, \n and all buckets have the same capacity.\n Your task is to use the buckets to empty the wells.\n Output the number of times you need to lower the buckets.\n\n Example 1:\n Input: \n grid : [[0,0,1,0], [0,1,0,0], [1,1,1,1]]\n bucket_capacity : 1\n Output: 6\n\n Example 2:\n Input: \n grid : [[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]]\n bucket_capacity : 2\n Output: 5\n \n Example 3:\n Input: \n grid : [[0,0,0], [0,0,0]]\n bucket_capacity : 5\n Output: 0\n\n Constraints:\n * all wells have the same length\n * 1 <= grid.length <= 10^2\n * 1 <= grid[:,1].length <= 10^2\n * grid[i][j] -> 0 | 1\n * 1 <= capacity <= 10\n */\nconst maxFill = (grid, capacity) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < grid.length; i++) {\n let m = 0\n for (let j = 0; j < grid[i].length; j++) {\n if (grid[i][j] == 1) { m++ }\n }\n while (m > 0) {\n m -= capacity;\n p++;\n }\n }\n return p\n}\n\n", "test": "const testMaxFill = () => {\n console.assert(\n maxFill(\n [\n [0, 0, 1, 0],\n [0, 1, 0, 0],\n [1, 1, 1, 1],\n ],\n 1\n ) === 6\n )\n console.assert(\n maxFill(\n [\n [0, 0, 1, 1],\n [0, 0, 0, 0],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n ],\n 2\n ) === 5\n )\n console.assert(\n maxFill(\n [\n [0, 0, 0],\n [0, 0, 0],\n ],\n 5\n ) === 0\n )\n console.assert(\n maxFill(\n [\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n ],\n 2\n ) === 4\n )\n console.assert(\n maxFill(\n [\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n ],\n 9\n ) === 2\n )\n}\n\ntestMaxFill()\n", "declaration": "\nconst maxFill = (grid, capacity) => {\n", "example_test": "const testMaxFill = () => {\n console.assert(\n maxFill(\n [\n [0, 0, 1, 0],\n [0, 1, 0, 0],\n [1, 1, 1, 1],\n ],\n 1\n ) === 6\n )\n console.assert(\n maxFill(\n [\n [0, 0, 1, 1],\n [0, 0, 0, 0],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n ],\n 2\n ) === 5\n )\n console.assert(\n maxFill(\n [\n [0, 0, 0],\n [0, 0, 0],\n ],\n 5\n ) === 0\n )\n}\ntestMaxFill()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < grid.length; i++) {\n let m = 0\n for (let j = 1; j < grid[i].length; j++) {\n if (grid[i][j] == 1) { m++ }\n }\n while (m > 0) {\n m -= capacity;\n p++;\n }\n }\n return p\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "maxFill", "signature": "const maxFill = (grid, capacity)", "docstring": "You are given a rectangular grid of wells. Each row represents a single well,\nand each 1 in a row represents a single unit of water.\nEach well has a corresponding bucket that can be used to extract water from it,\nand all buckets have the same capacity.\nYour task is to use the buckets to empty the wells.\nOutput the number of times you need to lower the buckets.\nExample 1:\nInput:\ngrid : [[0,0,1,0], [0,1,0,0], [1,1,1,1]]\nbucket_capacity : 1\nOutput: 6\nExample 2:\nInput:\ngrid : [[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]]\nbucket_capacity : 2\nOutput: 5\nExample 3:\nInput:\ngrid : [[0,0,0], [0,0,0]]\nbucket_capacity : 5\nOutput: 0\nConstraints:\n* all wells have the same length\n* 1 <= grid.length <= 10^2\n* 1 <= grid[:,1].length <= 10^2\n* grid[i][j] -> 0 | 1\n* 1 <= capacity <= 10", "instruction": "Write a JavaScript function `const maxFill = (grid, capacity)` to solve the following problem:\nYou are given a rectangular grid of wells. Each row represents a single well,\nand each 1 in a row represents a single unit of water.\nEach well has a corresponding bucket that can be used to extract water from it,\nand all buckets have the same capacity.\nYour task is to use the buckets to empty the wells.\nOutput the number of times you need to lower the buckets.\nExample 1:\nInput:\ngrid : [[0,0,1,0], [0,1,0,0], [1,1,1,1]]\nbucket_capacity : 1\nOutput: 6\nExample 2:\nInput:\ngrid : [[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]]\nbucket_capacity : 2\nOutput: 5\nExample 3:\nInput:\ngrid : [[0,0,0], [0,0,0]]\nbucket_capacity : 5\nOutput: 0\nConstraints:\n* all wells have the same length\n* 1 <= grid.length <= 10^2\n* 1 <= grid[:,1].length <= 10^2\n* grid[i][j] -> 0 | 1\n* 1 <= capacity <= 10"} +{"task_id": "JavaScript/116", "prompt": "/*\n In this Kata, you have to sort an array of non-negative integers according to\n number of ones in their binary representation in ascending order.\n For similar number of ones, sort based on decimal value.\n\n It must be implemented like this:\n >>> sortArray([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]\n >>> sortArray([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]\n >>> sortArray([1, 0, 2, 3, 4]) [0, 1, 2, 3, 4]\n */\nconst sortArray = (arr) => {\n", "canonical_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n let w1 = p[ind].toString(2)\n let f1 = 0\n for (let u = 0; u < w1.length; u++) {\n if (w1[u] == '1') { f1++ }\n }\n let w2 = p[k].toString(2)\n let f2 = 0\n for (let u = 0; u < w2.length; u++) {\n if (w2[u] == '1') { f2++ }\n }\n if (f2 < f1 || (f1 == f2 && p[k] < p[ind])) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "test": "const testSortArray = () => {\n console.assert(\n JSON.stringify(sortArray([1, 5, 2, 3, 4])) ===\n JSON.stringify([1, 2, 4, 3, 5])\n )\n\n console.assert(\n JSON.stringify(sortArray([-2, -3, -4, -5, -6])) ===\n JSON.stringify([-4, -2, -6, -5, -3])\n )\n console.assert(\n JSON.stringify(sortArray([1, 0, 2, 3, 4])) ===\n JSON.stringify([0, 1, 2, 4, 3])\n )\n console.assert(JSON.stringify(sortArray([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(sortArray([2, 5, 77, 4, 5, 3, 5, 7, 2, 3, 4])) ===\n JSON.stringify([2, 2, 4, 4, 3, 3, 5, 5, 5, 7, 77])\n )\n console.assert(\n JSON.stringify(sortArray([3, 6, 44, 12, 32, 5])) ===\n JSON.stringify([32, 3, 5, 6, 12, 44])\n )\n console.assert(\n JSON.stringify(sortArray([2, 4, 8, 16, 32])) ===\n JSON.stringify([2, 4, 8, 16, 32])\n )\n console.assert(\n JSON.stringify(sortArray([2, 4, 8, 16, 32])) ===\n JSON.stringify([2, 4, 8, 16, 32])\n )\n}\n\ntestSortArray()\n", "declaration": "\nconst sortArray = (arr) => {\n", "example_test": "const testSortArray = () => {\n console.assert(\n JSON.stringify(sortArray([1, 5, 2, 3, 4])) ===\n JSON.stringify([1, 2, 4, 3, 5])\n )\n console.assert(\n JSON.stringify(sortArray([-2, -3, -4, -5, -6])) ===\n JSON.stringify([-4, -2, -6, -5, -3])\n )\n console.assert(\n JSON.stringify(sortArray([1, 0, 2, 3, 4])) ===\n JSON.stringify([0, 1, 2, 4, 3])\n )\n}\ntestSortArray()\n", "buggy_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n let w1 = p[ind].toString(2)\n let f1 = 0\n for (let u = 0; u < w1.length; u++) {\n if (w1[u] == '1') { f1++ }\n }\n let w2 = p[ind].toString(2)\n let f2 = 0\n for (let u = 0; u < w2.length; u++) {\n if (w2[u] == '1') { f2++ }\n }\n if (f2 < f1 || (f1 == f2 && p[k] < p[ind])) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return arr\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "sortArray", "signature": "const sortArray = (arr)", "docstring": "In this Kata, you have to sort an array of non-negative integers according to\nnumber of ones in their binary representation in ascending order.\nFor similar number of ones, sort based on decimal value.\nIt must be implemented like this:\n>>> sortArray([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]\n>>> sortArray([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]\n>>> sortArray([1, 0, 2, 3, 4]) [0, 1, 2, 3, 4]", "instruction": "Write a JavaScript function `const sortArray = (arr)` to solve the following problem:\nIn this Kata, you have to sort an array of non-negative integers according to\nnumber of ones in their binary representation in ascending order.\nFor similar number of ones, sort based on decimal value.\nIt must be implemented like this:\n>>> sortArray([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]\n>>> sortArray([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]\n>>> sortArray([1, 0, 2, 3, 4]) [0, 1, 2, 3, 4]"} +{"task_id": "JavaScript/117", "prompt": "/*Given a string s and a natural number n, you have been tasked to implement \n a function that returns a list of all words from string s that contain exactly \n n consonants, in order these words appear in the string s.\n If the string s is empty then the function should return an empty list.\n Note: you may assume the input string contains only letters and spaces.\n Examples:\n selectWords(\"Mary had a little lamb\", 4) ==> [\"little\"]\n selectWords(\"Mary had a little lamb\", 3) ==> [\"Mary\")\n selectWords(\"simple white space\", 2) ==> []\n selectWords(\"Hello world\", 4) ==> [\"world\"]\n selectWords(\"Uncle sam\", 3) ==> [\"Uncle\"]\n */\nconst selectWords = (s, n) => {\n", "canonical_solution": " let t = s.split(/\\s/)\n if (s == '') { return [] }\n let k = []\n for (let i = 0; i < t.length; i++) {\n let l = 0\n for (let j = 0; j < t[i].length; j++) {\n if (t[i][j] != 'a' && t[i][j] != 'e' && t[i][j] != 'i' && t[i][j] != 'o' && t[i][j] != 'u' && t[i][j] != 'A' &&\n t[i][j] != 'U' && t[i][j] != 'O' && t[i][j] != 'I' && t[i][j] != 'E') {\n l++\n }\n }\n if (l == n) { k.push(t[i]) }\n }\n return k\n}\n\n", "test": "const testSelectWords = () => {\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 4)) ===\n JSON.stringify(['little'])\n )\n console.assert(\n JSON.stringify(selectWords('simple white space', 2)) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(selectWords('Hello world', 4)) === JSON.stringify(['world'])\n )\n console.assert(\n JSON.stringify(selectWords('Uncle sam', 3)) === JSON.stringify(['Uncle'])\n )\n\n console.assert(\n JSON.stringify(selectWords('a b c d e f', 1)) ===\n JSON.stringify(['b', 'c', 'd', 'f'])\n )\n\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 3)) ===\n JSON.stringify(['Mary', 'lamb'])\n )\n console.assert(JSON.stringify(selectWords('', 4)) === JSON.stringify([]))\n}\n\ntestSelectWords()\n", "declaration": "\nconst selectWords = (s, n) => {\n", "example_test": "const testSelectWords = () => {\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 4)) ===\n JSON.stringify(['little'])\n )\n console.assert(\n JSON.stringify(selectWords('simple white space', 2)) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(selectWords('Hello world', 4)) === JSON.stringify(['world'])\n )\n console.assert(\n JSON.stringify(selectWords('Uncle sam', 3)) === JSON.stringify(['Uncle'])\n )\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 3)) ===\n JSON.stringify(['Mary', 'lamb'])\n )\n}\ntestSelectWords()\n", "buggy_solution": " let t = s.split(/\\s/)\n if (s == '') { return [] }\n let k = []\n for (let i = 0; i < t.length; i++) {\n let l = 0\n for (let j = 0; j < t[i].length; j++) {\n if (t[i][j] != 'a' || t[i][j] != 'e' || t[i][j] != 'i' || t[i][j] != 'o' || t[i][j] != 'u' || t[i][j] != 'A' ||\n t[i][j] != 'U' || t[i][j] != 'O' || t[i][j] != 'I' || t[i][j] != 'E') {\n l++\n }\n }\n if (l == n) { k.push(t[i]) }\n }\n return k\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "selectWords", "signature": "const selectWords = (s, n)", "docstring": "Given a string s and a natural number n, you have been tasked to implement\na function that returns a list of all words from string s that contain exactly\nn consonants, in order these words appear in the string s.\nIf the string s is empty then the function should return an empty list.\nNote: you may assume the input string contains only letters and spaces.\nExamples:\nselectWords(\"Mary had a little lamb\", 4) ==> [\"little\"]\nselectWords(\"Mary had a little lamb\", 3) ==> [\"Mary\")\nselectWords(\"simple white space\", 2) ==> []\nselectWords(\"Hello world\", 4) ==> [\"world\"]\nselectWords(\"Uncle sam\", 3) ==> [\"Uncle\"]", "instruction": "Write a JavaScript function `const selectWords = (s, n)` to solve the following problem:\nGiven a string s and a natural number n, you have been tasked to implement\na function that returns a list of all words from string s that contain exactly\nn consonants, in order these words appear in the string s.\nIf the string s is empty then the function should return an empty list.\nNote: you may assume the input string contains only letters and spaces.\nExamples:\nselectWords(\"Mary had a little lamb\", 4) ==> [\"little\"]\nselectWords(\"Mary had a little lamb\", 3) ==> [\"Mary\")\nselectWords(\"simple white space\", 2) ==> []\nselectWords(\"Hello world\", 4) ==> [\"world\"]\nselectWords(\"Uncle sam\", 3) ==> [\"Uncle\"]"} +{"task_id": "JavaScript/118", "prompt": "/*You are given a word. Your task is to find the closest vowel that stands between \n two consonants from the right side of the word (case sensitive).\n \n Vowels in the beginning and ending doesn't count. Return empty string if you didn't\n find any vowel met the above condition. \n\n You may assume that the given string contains English letter only.\n\n Example:\n getClosestVowel(\"yogurt\") ==> \"u\"\n getClosestVowel(\"FULL\") ==> \"U\"\n getClosestVowel(\"quick\") ==> \"\"\n getClosestVowel(\"ab\") ==> \"\"\n */\nconst getClosestVowel = (word) => {\n", "canonical_solution": " for (let i = word.length - 2; i > 0; i--) {\n if (\n !(word[i] != 'a' && word[i] != 'e' && word[i] != 'i' && word[i] != 'o' && word[i] != 'u' && word[i] != 'A' &&\n word[i] != 'U' && word[i] != 'O' && word[i] != 'I' && word[i] != 'E')\n &&\n (word[i + 1] != 'a' && word[i + 1] != 'e' && word[i + 1] != 'i' && word[i + 1] != 'o' && word[i + 1] != 'u' && word[i + 1] != 'A' &&\n word[i + 1] != 'U' && word[i + 1] != 'O' && word[i + 1] != 'I' && word[i + 1] != 'E')\n &&\n (word[i - 1] != 'a' && word[i - 1] != 'e' && word[i - 1] != 'i' && word[i - 1] != 'o' && word[i - 1] != 'u' && word[i - 1] != 'A' &&\n word[i - 1] != 'U' && word[i - 1] != 'O' && word[i - 1] != 'I' && word[i - 1] != 'E')\n ) {\n return word[i]\n }\n }\n return ''\n}\n\n", "test": "const testGetClosestVowel = () => {\n console.assert(getClosestVowel('yogurt') === 'u')\n console.assert(getClosestVowel('full') === 'u')\n console.assert(getClosestVowel('easy') === '')\n console.assert(getClosestVowel('eAsy') === '')\n console.assert(getClosestVowel('ali') === '')\n console.assert(getClosestVowel('bad') === 'a')\n console.assert(getClosestVowel('most') === 'o')\n console.assert(getClosestVowel('ab') === '')\n console.assert(getClosestVowel('ba') === '')\n console.assert(getClosestVowel('quick') === '')\n console.assert(getClosestVowel('anime') === 'i')\n console.assert(getClosestVowel('Asia') === '')\n console.assert(getClosestVowel('Above') === 'o')\n}\n\ntestGetClosestVowel()\n", "declaration": "\nconst getClosestVowel = (word) => {\n", "example_test": "const testGetClosestVowel = () => {\n console.assert(getClosestVowel('yogurt') === 'u')\n console.assert(getClosestVowel('FULL') === 'U')\n console.assert(getClosestVowel('ab') === '')\n console.assert(getClosestVowel('quick') === '')\n}\ntestGetClosestVowel()\n", "buggy_solution": " for (let i = word.length - 2; i > 0; i--) {\n if (\n (word[i] != 'a' && word[i] != 'e' && word[i] != 'i' && word[i] != 'o' && word[i] != 'u' && word[i] != 'A' &&\n word[i] != 'U' && word[i] != 'O' && word[i] != 'I' && word[i] != 'E')\n &&\n (word[i + 1] != 'a' && word[i + 1] != 'e' && word[i + 1] != 'i' && word[i + 1] != 'o' && word[i + 1] != 'u' && word[i + 1] != 'A' &&\n word[i + 1] != 'U' && word[i + 1] != 'O' && word[i + 1] != 'I' && word[i + 1] != 'E')\n &&\n (word[i - 1] != 'a' && word[i - 1] != 'e' && word[i - 1] != 'i' && word[i - 1] != 'o' && word[i - 1] != 'u' && word[i - 1] != 'A' &&\n word[i - 1] != 'U' && word[i - 1] != 'O' && word[i - 1] != 'I' && word[i - 1] != 'E')\n ) {\n return word[i]\n }\n }\n return ' '\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "getClosestVowel", "signature": "const getClosestVowel = (word)", "docstring": "You are given a word. Your task is to find the closest vowel that stands between\ntwo consonants from the right side of the word (case sensitive).\nVowels in the beginning and ending doesn't count. Return empty string if you didn't\nfind any vowel met the above condition.\nYou may assume that the given string contains English letter only.\nExample:\ngetClosestVowel(\"yogurt\") ==> \"u\"\ngetClosestVowel(\"FULL\") ==> \"U\"\ngetClosestVowel(\"quick\") ==> \"\"\ngetClosestVowel(\"ab\") ==> \"\"", "instruction": "Write a JavaScript function `const getClosestVowel = (word)` to solve the following problem:\nYou are given a word. Your task is to find the closest vowel that stands between\ntwo consonants from the right side of the word (case sensitive).\nVowels in the beginning and ending doesn't count. Return empty string if you didn't\nfind any vowel met the above condition.\nYou may assume that the given string contains English letter only.\nExample:\ngetClosestVowel(\"yogurt\") ==> \"u\"\ngetClosestVowel(\"FULL\") ==> \"U\"\ngetClosestVowel(\"quick\") ==> \"\"\ngetClosestVowel(\"ab\") ==> \"\""} +{"task_id": "JavaScript/119", "prompt": "/* You are given a list of two strings, both strings consist of open\n parentheses '(' or close parentheses ')' only.\n Your job is to check if it is possible to concatenate the two strings in\n some order, that the resulting string will be good.\n A string S is considered to be good if and only if all parentheses in S\n are balanced. For example: the string '(())()' is good, while the string\n '())' is not.\n Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.\n Examples:\n matchParens(['()(', ')']) == 'Yes'\n matchParens([')', ')']) == 'No'\n */\nconst matchParens = (lst) => {\n", "canonical_solution": " let w1 = lst[0] + lst[1]\n let y = 0\n let u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'Yes' }\n w1 = lst[1] + lst[0]\n y = 0\n u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'Yes' }\n return 'No'\n}\n\n", "test": "const testMatchParens = () => {\n console.assert(matchParens(['()(', ')']) === 'Yes')\n console.assert(matchParens([')', ')']) === 'No')\n console.assert(matchParens(['(()(())', '())())']) === 'No')\n console.assert(matchParens([')())', '(()()(']) === 'Yes')\n console.assert(matchParens(['(())))', '(()())((']) === 'Yes')\n console.assert(matchParens(['()', '())']) === 'No')\n console.assert(matchParens(['(()(', '()))()']) === 'Yes')\n console.assert(matchParens(['((((', '((())']) === 'No')\n console.assert(matchParens([')(()', '(()(']) === 'No')\n console.assert(matchParens([')(', ')(']) === 'No')\n console.assert(matchParens(['(', ')']) === 'Yes')\n console.assert(matchParens([')', '(']) === 'Yes')\n}\ntestMatchParens()\n", "declaration": "\nconst matchParens = (lst) => {\n", "example_test": "const testMatchParens = () => {\n console.assert(matchParens(['()(', ')']) === 'Yes')\n console.assert(matchParens([')', ')']) === 'No')\n}\ntestMatchParens()\n", "buggy_solution": " let w1 = lst[0] + lst[1]\n let y = 0\n let u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'yes' }\n w1 = lst[1] + lst[0]\n y = 0\n u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'no' }\n return 'yes'\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "matchParens", "signature": "const matchParens = (lst)", "docstring": "You are given a list of two strings, both strings consist of open\nparentheses '(' or close parentheses ')' only.\nYour job is to check if it is possible to concatenate the two strings in\nsome order, that the resulting string will be good.\nA string S is considered to be good if and only if all parentheses in S\nare balanced. For example: the string '(())()' is good, while the string\n'())' is not.\nReturn 'Yes' if there's a way to make a good string, and return 'No' otherwise.\nExamples:\nmatchParens(['()(', ')']) == 'Yes'\nmatchParens([')', ')']) == 'No'", "instruction": "Write a JavaScript function `const matchParens = (lst)` to solve the following problem:\nYou are given a list of two strings, both strings consist of open\nparentheses '(' or close parentheses ')' only.\nYour job is to check if it is possible to concatenate the two strings in\nsome order, that the resulting string will be good.\nA string S is considered to be good if and only if all parentheses in S\nare balanced. For example: the string '(())()' is good, while the string\n'())' is not.\nReturn 'Yes' if there's a way to make a good string, and return 'No' otherwise.\nExamples:\nmatchParens(['()(', ')']) == 'Yes'\nmatchParens([')', ')']) == 'No'"} +{"task_id": "JavaScript/120", "prompt": "/*\n Given an array arr of integers and a positive integer k, return a sorted list \n of length k with the maximum k numbers in arr.\n\n Example 1:\n\n Input: arr = [-3, -4, 5], k = 3\n Output: [-4, -3, 5]\n\n Example 2:\n\n Input: arr = [4, -4, 4], k = 2\n Output: [4, 4]\n\n Example 3:\n\n Input: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1\n Output: [2]\n\n Note:\n 1. The length of the array will be in the range of [1, 1000].\n 2. The elements in the array will be in the range of [-1000, 1000].\n 3. 0 <= k <= len(arr)\n */\nconst maximum = (arr, k) => {\n", "canonical_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n if (k == 0) { return [] }\n return p.slice(-k)\n}\n\n", "test": "const testMaximum = () => {\n console.assert(\n JSON.stringify(maximum([-3, -4, 5], 3)) === JSON.stringify([-4, -3, 5])\n )\n console.assert(\n JSON.stringify(maximum([4, -4, 4], 2)) === JSON.stringify([4, 4])\n )\n console.assert(\n JSON.stringify(maximum([-3, 2, 1, 2, -1, -2, 1], 1)) === JSON.stringify([2])\n )\n console.assert(\n JSON.stringify(maximum([123, -123, 20, 0, 1, 2, -3], 3)) ===\n JSON.stringify([2, 20, 123])\n )\n console.assert(\n JSON.stringify(maximum([-123, 20, 0, 1, 2, -3], 4)) ===\n JSON.stringify([0, 1, 2, 20])\n )\n console.assert(\n JSON.stringify(maximum([5, 15, 0, 3, -13, -8, 0], 7)) ===\n JSON.stringify([-13, -8, 0, 0, 3, 5, 15])\n )\n console.assert(\n JSON.stringify(maximum([-1, 0, 2, 5, 3, -10], 2)) === JSON.stringify([3, 5])\n )\n console.assert(\n JSON.stringify(maximum([1, 0, 5, -7], 1)) === JSON.stringify([5])\n )\n console.assert(JSON.stringify(maximum([4, -4], 2)) === JSON.stringify([-4, 4]))\n console.assert(\n JSON.stringify(maximum([-10, 10], 2)) === JSON.stringify([-10, 10])\n )\n console.assert(\n JSON.stringify(maximum([1, 2, 3, -23, 243, -400, 0], 0)) ===\n JSON.stringify([])\n )\n}\n\ntestMaximum()\n", "declaration": "\nconst maximum = (arr, k) => {\n", "example_test": "const testMaximum = () => {\n console.assert(\n JSON.stringify(maximum([-3, -4, 5], 3)) === JSON.stringify([-4, -3, 5])\n )\n console.assert(\n JSON.stringify(maximum([4, -4, 4], 2)) === JSON.stringify([4, 4])\n )\n console.assert(\n JSON.stringify(maximum([-3, 2, 1, 2, -1, -2, 1], 1)) === JSON.stringify([2])\n )\n}\ntestMaximum()\n", "buggy_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n p[j] = p[ind]\n }\n }\n if (k == 0) { return [] }\n return p.slice(-k)\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "maximum", "signature": "const maximum = (arr, k)", "docstring": "Given an array arr of integers and a positive integer k, return a sorted list\nof length k with the maximum k numbers in arr.\nExample 1:\nInput: arr = [-3, -4, 5], k = 3\nOutput: [-4, -3, 5]\nExample 2:\nInput: arr = [4, -4, 4], k = 2\nOutput: [4, 4]\nExample 3:\nInput: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1\nOutput: [2]\nNote:\n1. The length of the array will be in the range of [1, 1000].\n2. The elements in the array will be in the range of [-1000, 1000].\n3. 0 <= k <= len(arr)", "instruction": "Write a JavaScript function `const maximum = (arr, k)` to solve the following problem:\nGiven an array arr of integers and a positive integer k, return a sorted list\nof length k with the maximum k numbers in arr.\nExample 1:\nInput: arr = [-3, -4, 5], k = 3\nOutput: [-4, -3, 5]\nExample 2:\nInput: arr = [4, -4, 4], k = 2\nOutput: [4, 4]\nExample 3:\nInput: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1\nOutput: [2]\nNote:\n1. The length of the array will be in the range of [1, 1000].\n2. The elements in the array will be in the range of [-1000, 1000].\n3. 0 <= k <= len(arr)"} +{"task_id": "JavaScript/121", "prompt": "/*Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions.\n \n\n Examples\n solution([5, 8, 7, 1]) ==> 12\n solution([3, 3, 3, 3, 3]) ==> 9\n solution([30, 13, 24, 321]) ==>0\n */\nconst solution = (lst) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < lst.length; i += 2) {\n if (lst[i] % 2 == 1) {\n p += lst[i]\n }\n }\n return p\n}\n\n", "test": "const testSolution = () => {\n console.assert(solution([5, 8, 7, 1]) === 12)\n console.assert(solution([3, 3, 3, 3, 3]) === 9)\n console.assert(solution([30, 13, 24, 321]) === 0)\n console.assert(solution([5, 9]) === 5)\n console.assert(solution([2, 4, 8]) === 0)\n console.assert(solution([30, 13, 23, 32]) === 23)\n console.assert(solution([3, 13, 2, 9]) === 3)\n}\n\ntestSolution()\n", "declaration": "\nconst solution = (lst) => {\n", "example_test": "const testSolution = () => {\n console.assert(solution([5, 8, 7, 1]) === 12)\n console.assert(solution([3, 3, 3, 3, 3]) === 9)\n console.assert(solution([30, 13, 24, 321]) === 0)\n}\ntestSolution()\n", "buggy_solution": " let p = 1\n for (let i = 0; i < lst.length; i += 2) {\n if (lst[i] % 2 == 1) {\n p += lst[i]\n }\n }\n return p\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "solution", "signature": "const solution = (lst)", "docstring": "Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions.\nExamples\nsolution([5, 8, 7, 1]) ==> 12\nsolution([3, 3, 3, 3, 3]) ==> 9\nsolution([30, 13, 24, 321]) ==>0", "instruction": "Write a JavaScript function `const solution = (lst)` to solve the following problem:\nGiven a non-empty list of integers, return the sum of all of the odd elements that are in even positions.\nExamples\nsolution([5, 8, 7, 1]) ==> 12\nsolution([3, 3, 3, 3, 3]) ==> 9\nsolution([30, 13, 24, 321]) ==>0"} +{"task_id": "JavaScript/122", "prompt": "/*\n Given a non-empty array of integers arr and an integer k, return\n the sum of the elements with at most two digits from the first k elements of arr.\n\n Example:\n\n Input: arr = [111,21,3,4000,5,6,7,8,9], k = 4\n Output: 24 # sum of 21 + 3\n\n Constraints:\n 1. 1 <= len(arr) <= 100\n 2. 1 <= k <= len(arr)\n */\nconst addElements = (arr, k) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < k; i++) {\n if (arr[i] < 100 && arr[i] > -100) { p += arr[i] }\n }\n return p\n}\n\n", "test": "const testAddElements = () => {\n console.assert(addElements([1, -2, -3, 41, 57, 76, 87, 88, 99], 3) === -4)\n console.assert(addElements([111, 121, 3, 4000, 5, 6], 2) === 0)\n console.assert(addElements([11, 21, 3, 90, 5, 6, 7, 8, 9], 4) === 125)\n console.assert(addElements([111, 21, 3, 4000, 5, 6, 7, 8, 9], 4) === 24)\n console.assert(addElements([1], 1) === 1)\n}\n\ntestAddElements()\n", "declaration": "\nconst addElements = (arr, k) => {\n", "example_test": "const testAddElements = () => {\n console.assert(addElements([111, 21, 3, 4000, 5, 6, 7, 8, 9], 4) === 24)\n}\ntestAddElements()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] < 100 && arr[i] > -100) { p += arr[i] }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "addElements", "signature": "const addElements = (arr, k)", "docstring": "Given a non-empty array of integers arr and an integer k, return\nthe sum of the elements with at most two digits from the first k elements of arr.\nExample:\nInput: arr = [111,21,3,4000,5,6,7,8,9], k = 4\nOutput: 24 # sum of 21 + 3\nConstraints:\n1. 1 <= len(arr) <= 100\n2. 1 <= k <= len(arr)", "instruction": "Write a JavaScript function `const addElements = (arr, k)` to solve the following problem:\nGiven a non-empty array of integers arr and an integer k, return\nthe sum of the elements with at most two digits from the first k elements of arr.\nExample:\nInput: arr = [111,21,3,4000,5,6,7,8,9], k = 4\nOutput: 24 # sum of 21 + 3\nConstraints:\n1. 1 <= len(arr) <= 100\n2. 1 <= k <= len(arr)"} +{"task_id": "JavaScript/123", "prompt": "/*\n Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence.\n\n The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined\n as follows: start with any positive integer n. Then each term is obtained from the \n previous term as follows: if the previous term is even, the next term is one half of \n the previous term. If the previous term is odd, the next term is 3 times the previous\n term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.\n\n Note: \n 1. Collatz(1) is [1].\n 2. returned list sorted in increasing order.\n\n For example:\n getOddCollatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.\n */\nconst getOddCollatz = (n) => {\n", "canonical_solution": " let p = []\n let t = n\n while (1) {\n let u = 0\n for (let i = 0; i < p.length; i++) {\n if (t == p[i]) {\n u = 1\n break;\n }\n }\n if (u == 1) { break }\n if (t % 2 == 1) { p.push(t); t = 3 * t + 1 }\n else { t = t / 2 }\n }\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "test": "const testGetOddCollatz = () => {\n console.assert(\n JSON.stringify(getOddCollatz(14)) === JSON.stringify([1, 5, 7, 11, 13, 17])\n )\n console.assert(JSON.stringify(getOddCollatz(5)) === JSON.stringify([1, 5]))\n console.assert(JSON.stringify(getOddCollatz(12)) === JSON.stringify([1, 3, 5]))\n console.assert(JSON.stringify(getOddCollatz(1)) === JSON.stringify([1]))\n}\n\ntestGetOddCollatz()\n", "declaration": "\nconst getOddCollatz = (n) => {\n", "example_test": "const testGetOddCollatz = () => {\n console.assert(JSON.stringify(getOddCollatz(5)) === JSON.stringify([1, 5]))\n}\ntestGetOddCollatz()\n", "buggy_solution": " let p = []\n let t = n\n while (1) {\n let u = 0\n for (let i = 0; i < p.length; i++) {\n if (t == p[i]) {\n u = 1\n break;\n }\n }\n if (u == 1) { break }\n if (t % 2 == 1) { p.push(t); t = 2 * t + 1 }\n else { t = t / 2 }\n }\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "getOddCollatz", "signature": "const getOddCollatz = (n)", "docstring": "Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence.\nThe Collatz conjecture is a conjecture in mathematics that concerns a sequence defined\nas follows: start with any positive integer n. Then each term is obtained from the\nprevious term as follows: if the previous term is even, the next term is one half of\nthe previous term. If the previous term is odd, the next term is 3 times the previous\nterm plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.\nNote:\n1. Collatz(1) is [1].\n2. returned list sorted in increasing order.\nFor example:\ngetOddCollatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.", "instruction": "Write a JavaScript function `const getOddCollatz = (n)` to solve the following problem:\nGiven a positive integer n, return a sorted list that has the odd numbers in collatz sequence.\nThe Collatz conjecture is a conjecture in mathematics that concerns a sequence defined\nas follows: start with any positive integer n. Then each term is obtained from the\nprevious term as follows: if the previous term is even, the next term is one half of\nthe previous term. If the previous term is odd, the next term is 3 times the previous\nterm plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.\nNote:\n1. Collatz(1) is [1].\n2. returned list sorted in increasing order.\nFor example:\ngetOddCollatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5."} +{"task_id": "JavaScript/124", "prompt": "/*You have to write a function which validates a given date string and\n returns true if the date is valid otherwise false.\n The date is valid if all of the following rules are satisfied:\n 1. The date string is not empty.\n 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n 3. The months should not be less than 1 or higher than 12.\n 4. The date should be in the format: mm-dd-yyyy\n\n for example: \n validDate('03-11-2000') => true\n\n validDate('15-01-2012') => false\n\n validDate('04-0-2040') => false\n\n validDate('06-04-2020') => true\n\n validDate('06/04/2020') => false\n */\nconst validDate = (date) => {\n", "canonical_solution": " let t = date.split(/-/)\n if (t.length != 3) { return false }\n if (t[0] < 1 || t[0] > 12 || t[1] < 1) { return false }\n if (t[0] == 2 && t[1] > 29) { return false }\n if ((t[0] == 1 || t[0] == 3 || t[0] == 5 || t[0] == 7 || t[0] == 8 || t[0] == 10 || t[0] == 12) && t[1] > 31) { return false }\n if ((t[0] == 4 || t[0] == 6 || t[0] == 9 || t[0] == 11) && t[1] > 30) { return false }\n return true\n}\n\n", "test": "const testValidDate = () => {\n console.assert(validDate('03-11-2000') === true)\n console.assert(validDate('15-01-2012') === false)\n console.assert(validDate('04-0-2040') === false)\n console.assert(validDate('06-04-2020') === true)\n console.assert(validDate('01-01-2007') === true)\n console.assert(validDate('03-32-2011') === false)\n console.assert(validDate('') === false)\n console.assert(validDate('04-31-3000') === false)\n console.assert(validDate('06-06-2005') === true)\n console.assert(validDate('21-31-2000') === false)\n console.assert(validDate('04-12-2003') === true)\n console.assert(validDate('04122003') === false)\n console.assert(validDate('20030412') === false)\n console.assert(validDate('2003-04') === false)\n console.assert(validDate('2003-04-12') === false)\n console.assert(validDate('04-2003') === false)\n}\n\ntestValidDate()\n", "declaration": "\nconst validDate = (date) => {\n", "example_test": "const testValidDate = () => {\n console.assert(validDate('03-11-2000') === true)\n console.assert(validDate('15-01-2012') === false)\n console.assert(validDate('04-0-2040') === false)\n console.assert(validDate('06-04-2020') === true)\n console.assert(validDate('06/04/2020') === false)\n}\ntestValidDate()\n", "buggy_solution": " let t = date.split(/-/)\n if (t.length != 3) { return false }\n if (t[1] < 1 || t[1] > 12 || t[0] < 1) { return false }\n if (t[1] == 2 && t[0] > 29) { return false }\n if ((t[1] == 1 || t[1] == 3 || t[1] == 5 || t[1] == 7 || t[1] == 8 || t[1] == 10 || t[1] == 12) && t[0] > 31) { return false }\n if ((t[1] == 4 || t[1] == 6 || t[1] == 9 || t[1] == 11) && t[0] > 30) { return false }\n return true\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "validDate", "signature": "const validDate = (date)", "docstring": "You have to write a function which validates a given date string and\nreturns true if the date is valid otherwise false.\nThe date is valid if all of the following rules are satisfied:\n1. The date string is not empty.\n2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n3. The months should not be less than 1 or higher than 12.\n4. The date should be in the format: mm-dd-yyyy\nfor example:\nvalidDate('03-11-2000') => true\nvalidDate('15-01-2012') => false\nvalidDate('04-0-2040') => false\nvalidDate('06-04-2020') => true\nvalidDate('06/04/2020') => false", "instruction": "Write a JavaScript function `const validDate = (date)` to solve the following problem:\nYou have to write a function which validates a given date string and\nreturns true if the date is valid otherwise false.\nThe date is valid if all of the following rules are satisfied:\n1. The date string is not empty.\n2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n3. The months should not be less than 1 or higher than 12.\n4. The date should be in the format: mm-dd-yyyy\nfor example:\nvalidDate('03-11-2000') => true\nvalidDate('15-01-2012') => false\nvalidDate('04-0-2040') => false\nvalidDate('06-04-2020') => true\nvalidDate('06/04/2020') => false"} +{"task_id": "JavaScript/125", "prompt": "/* Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you\n should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the\n alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25\n Examples\n splitWords(\"Hello world!\") \u279e [\"Hello\", \"world!\"]\n splitWords(\"Hello,world!\") \u279e [\"Hello\", \"world!\"]\n splitWords(\"abcdef\") == 3\n */\nconst splitWords = (txt) => {\n", "canonical_solution": " let t = txt.split(/\\s/)\n if (t.length > 1) {\n return t\n } else {\n t = txt.split(/,/)\n if (t.length > 1) {\n return t\n } else {\n let p = 0\n for (let i = 0; i < txt.length; i++) {\n let m = txt[i].charCodeAt()\n if (m >= 97 && m <= 122 && m % 2 == 0) {\n p++\n }\n }\n return p\n }\n }\n}\n\n", "test": "const testSplitWords = () => {\n console.assert(\n JSON.stringify(splitWords('Hello world!')) ===\n JSON.stringify(['Hello', 'world!'])\n )\n console.assert(\n JSON.stringify(splitWords('Hello,world!')) ===\n JSON.stringify(['Hello', 'world!'])\n )\n console.assert(\n JSON.stringify(splitWords('Hello world,!')) ===\n JSON.stringify(['Hello', 'world,!'])\n )\n console.assert(\n JSON.stringify(splitWords('Hello,Hello,world !')) ===\n JSON.stringify(['Hello,Hello,world', '!'])\n )\n console.assert(JSON.stringify(splitWords('abcdef')) === JSON.stringify(3))\n console.assert(JSON.stringify(splitWords('aaabb')) === JSON.stringify(2))\n console.assert(JSON.stringify(splitWords('aaaBb')) === JSON.stringify(1))\n console.assert(JSON.stringify(splitWords('')) === JSON.stringify(0))\n}\n\ntestSplitWords()\n", "declaration": "\nconst splitWords = (txt) => {\n", "example_test": "const testSplitWords = () => {\n console.assert(\n JSON.stringify(splitWords('Hello world!')) ===\n JSON.stringify(['Hello', 'world!'])\n )\n console.assert(\n JSON.stringify(splitWords('Hello,world!')) ===\n JSON.stringify(['Hello', 'world!'])\n )\n console.assert(JSON.stringify(splitWords('abcdef')) === JSON.stringify(3))\n}\ntestSplitWords()\n", "buggy_solution": " let t = txt.split(/,/)\n if (t.length > 1) {\n return t\n } else {\n t = txt.split(/\\s/)\n if (t.length > 1) {\n return t\n } else {\n let p = 0\n for (let i = 0; i < txt.length; i++) {\n let m = txt[i].charCodeAt()\n if (m >= 97 && m <= 122 && m % 2 == 0) {\n p++\n }\n }\n return p\n }\n }\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "splitWords", "signature": "const splitWords = (txt)", "docstring": "Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you\nshould split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the\nalphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25\nExamples\nsplitWords(\"Hello world!\") \u279e [\"Hello\", \"world!\"]\nsplitWords(\"Hello,world!\") \u279e [\"Hello\", \"world!\"]\nsplitWords(\"abcdef\") == 3", "instruction": "Write a JavaScript function `const splitWords = (txt)` to solve the following problem:\nGiven a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you\nshould split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the\nalphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25\nExamples\nsplitWords(\"Hello world!\") \u279e [\"Hello\", \"world!\"]\nsplitWords(\"Hello,world!\") \u279e [\"Hello\", \"world!\"]\nsplitWords(\"abcdef\") == 3"} +{"task_id": "JavaScript/126", "prompt": "/* Given a list of numbers, return whether or not they are sorted\n in ascending order. If list has more than 1 duplicate of the same\n number, return false. Assume no negative numbers and only integers.\n Examples\n isSorted([5]) \u279e true\n isSorted([1, 2, 3, 4, 5]) \u279e true\n isSorted([1, 3, 2, 4, 5]) \u279e false\n isSorted([1, 2, 3, 4, 5, 6]) \u279e true\n isSorted([1, 2, 3, 4, 5, 6, 7]) \u279e true\n isSorted([1, 3, 2, 4, 5, 6, 7]) \u279e false\n isSorted([1, 2, 2, 3, 3, 4]) \u279e true\n isSorted([1, 2, 2, 2, 3, 4]) \u279e false\n */\nconst isSorted = (lst) => {\n", "canonical_solution": " if (lst.length == 0) { return true }\n let dup = 1\n let pre = lst[0]\n for (let i = 1; i < lst.length; i++) {\n if (lst[i] < pre) { return false }\n if (lst[i] == pre) {\n dup += 1;\n if (dup == 3) { return false }\n } else {\n pre = lst[i]\n dup = 1\n }\n }\n return true\n}\n\n", "test": "const testIsSorted = () => {\n console.assert(isSorted([5]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5]) === false)\n console.assert(isSorted([1, 2, 3, 4, 5, 6]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5, 6, 7]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5, 6, 7]) === false)\n console.assert(isSorted([]) === true)\n console.assert(isSorted([1]) === true)\n console.assert(isSorted([3, 2, 1]) === false)\n console.assert(isSorted([1, 2, 2, 2, 3, 4]) === false)\n console.assert(isSorted([1, 2, 3, 3, 3, 4]) === false)\n console.assert(isSorted([1, 2, 2, 3, 3, 4]) === true)\n console.assert(isSorted([1, 2, 3, 4]) === true)\n}\n\ntestIsSorted()\n", "declaration": "\nconst isSorted = (lst) => {\n", "example_test": "const testIsSorted = () => {\n console.assert(isSorted([5]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5]) === false)\n console.assert(isSorted([1, 2, 3, 4, 5, 6]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5, 6, 7]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5, 6, 7]) === false)\n console.assert(isSorted([1, 2, 2, 2, 3, 4]) === false)\n console.assert(isSorted([1, 2, 2, 3, 3, 4]) === true)\n}\ntestIsSorted()\n", "buggy_solution": " if (lst.length == 0) { return true }\n let dup = 1\n let pre = lst[0]\n for (let i = 1; i < lst.length; i++) {\n if (lst[i] < pre) { return false }\n if (lst[i] == pre) {\n dup += 1;\n if (dup == 3) { return false }\n } else {\n pre = lst[i]\n }\n }\n return true\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "isSorted", "signature": "const isSorted = (lst)", "docstring": "Given a list of numbers, return whether or not they are sorted\nin ascending order. If list has more than 1 duplicate of the same\nnumber, return false. Assume no negative numbers and only integers.\nExamples\nisSorted([5]) \u279e true\nisSorted([1, 2, 3, 4, 5]) \u279e true\nisSorted([1, 3, 2, 4, 5]) \u279e false\nisSorted([1, 2, 3, 4, 5, 6]) \u279e true\nisSorted([1, 2, 3, 4, 5, 6, 7]) \u279e true\nisSorted([1, 3, 2, 4, 5, 6, 7]) \u279e false\nisSorted([1, 2, 2, 3, 3, 4]) \u279e true\nisSorted([1, 2, 2, 2, 3, 4]) \u279e false", "instruction": "Write a JavaScript function `const isSorted = (lst)` to solve the following problem:\nGiven a list of numbers, return whether or not they are sorted\nin ascending order. If list has more than 1 duplicate of the same\nnumber, return false. Assume no negative numbers and only integers.\nExamples\nisSorted([5]) \u279e true\nisSorted([1, 2, 3, 4, 5]) \u279e true\nisSorted([1, 3, 2, 4, 5]) \u279e false\nisSorted([1, 2, 3, 4, 5, 6]) \u279e true\nisSorted([1, 2, 3, 4, 5, 6, 7]) \u279e true\nisSorted([1, 3, 2, 4, 5, 6, 7]) \u279e false\nisSorted([1, 2, 2, 3, 3, 4]) \u279e true\nisSorted([1, 2, 2, 2, 3, 4]) \u279e false"} +{"task_id": "JavaScript/127", "prompt": "/*You are given two intervals,\n where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\n The given intervals are closed which means that the interval (start, end)\n includes both start and end.\n For each given interval, it is assumed that its start is less or equal its end.\n Your task is to determine whether the length of intersection of these two \n intervals is a prime number.\n Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\n which its length is 1, which not a prime number.\n If the length of the intersection is a prime number, return \"YES\",\n otherwise, return \"NO\".\n If the two intervals don't intersect, return \"NO\".\n\n\n [input/output] samples:\n intersection((1, 2), (2, 3)) ==> \"NO\"\n intersection((-1, 1), (0, 4)) ==> \"NO\"\n intersection((-3, -1), (-5, 5)) ==> \"YES\"\n */\nconst intersection = (interval1, interval2) => {\n", "canonical_solution": " let lo = interval1[0]\n if (interval2[0] > lo) { lo = interval2[0] }\n let hi = interval1[1]\n if (interval2[1] < hi) { hi = interval2[1] }\n let len = 0\n if (hi > lo) { len = hi - lo }\n if (len == 1 || len == 0) { return 'NO' }\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { return 'NO' }\n }\n return 'YES'\n}\n\n", "test": "const testIntersection = () => {\n console.assert(intersection([1, 2], [2, 3]) === 'NO')\n console.assert(intersection([-1, 1], [0, 4]) === 'NO')\n console.assert(intersection([-3, -1], [-5, 5]) === 'YES')\n console.assert(intersection([-2, 2], [-4, 0]) === 'YES')\n console.assert(intersection([-11, 2], [-1, -1]) === 'NO')\n console.assert(intersection([1, 2], [3, 5]) === 'NO')\n console.assert(intersection([1, 2], [1, 2]) === 'NO')\n console.assert(intersection([-2, -2], [-3, -2]) === 'NO')\n}\n\ntestIntersection()\n", "declaration": "\nconst intersection = (interval1, interval2) => {\n", "example_test": "const testIntersection = () => {\n console.assert(intersection([1, 2], [2, 3]) === 'NO')\n console.assert(intersection([-1, 1], [0, 4]) === 'NO')\n console.assert(intersection([-3, -1], [-5, 5]) === 'YES')\n}\ntestIntersection()\n", "buggy_solution": " let lo = interval1[0]\n if (interval2[0] > lo) { lo = interval2[0] }\n let hi = interval1[1]\n if (interval2[1] < hi) { hi = interval2[1] }\n let len = 0\n if (hi > lo) { len = hi }\n if (len == 1 || len == 0) { return 'NO' }\n return 'YES'\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "intersection", "signature": "const intersection = (interval1, interval2)", "docstring": "You are given two intervals,\nwhere each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\nThe given intervals are closed which means that the interval (start, end)\nincludes both start and end.\nFor each given interval, it is assumed that its start is less or equal its end.\nYour task is to determine whether the length of intersection of these two\nintervals is a prime number.\nExample, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\nwhich its length is 1, which not a prime number.\nIf the length of the intersection is a prime number, return \"YES\",\notherwise, return \"NO\".\nIf the two intervals don't intersect, return \"NO\".\n[input/output] samples:\nintersection((1, 2), (2, 3)) ==> \"NO\"\nintersection((-1, 1), (0, 4)) ==> \"NO\"\nintersection((-3, -1), (-5, 5)) ==> \"YES\"", "instruction": "Write a JavaScript function `const intersection = (interval1, interval2)` to solve the following problem:\nYou are given two intervals,\nwhere each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\nThe given intervals are closed which means that the interval (start, end)\nincludes both start and end.\nFor each given interval, it is assumed that its start is less or equal its end.\nYour task is to determine whether the length of intersection of these two\nintervals is a prime number.\nExample, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\nwhich its length is 1, which not a prime number.\nIf the length of the intersection is a prime number, return \"YES\",\notherwise, return \"NO\".\nIf the two intervals don't intersect, return \"NO\".\n[input/output] samples:\nintersection((1, 2), (2, 3)) ==> \"NO\"\nintersection((-1, 1), (0, 4)) ==> \"NO\"\nintersection((-3, -1), (-5, 5)) ==> \"YES\""} +{"task_id": "JavaScript/128", "prompt": "/*\n You are given an array arr of integers and you need to return\n sum of magnitudes of integers multiplied by product of all signs\n of each number in the array, represented by 1, -1 or 0.\n Note: return null for empty arr.\n\n Example:\n >>> prodSigns([1, 2, 2, -4]) == -9\n >>> prodSigns([0, 1]) == 0\n >>> prodSigns([]) == null\n */\nconst prodSigns = (arr) => {\n", "canonical_solution": " if (arr.length == 0) { return null }\n let n = 1\n let s = 0\n for (let i = 0; i < arr.length; i++) {\n s += arr[i]\n if (arr[i] == 0) { return 0 }\n if (arr[i] < 0) { n = -n; s -= 2 * arr[i] }\n }\n return s * n\n}\n\n", "test": "const testProdSigns = () => {\n console.assert(prodSigns([1, 2, 2, -4]) === -9)\n console.assert(prodSigns([0, 1]) === 0)\n console.assert(prodSigns([1, 1, 1, 2, 3, -1, 1]) === -10)\n console.assert(prodSigns([]) === null)\n console.assert(prodSigns([2, 4, 1, 2, -1, -1, 9]) === 20)\n console.assert(prodSigns([-1, 1, -1, 1]) === 4)\n console.assert(prodSigns([-1, 1, 1, 1]) === -4)\n console.assert(prodSigns([-1, 1, 1, 0]) === 0)\n}\n\ntestProdSigns()\n", "declaration": "\nconst prodSigns = (arr) => {\n", "example_test": "const testProdSigns = () => {\n console.assert(prodSigns([1, 2, 2, -4]) === -9)\n console.assert(prodSigns([0, 1]) === 0)\n console.assert(prodSigns([]) === null)\n}\ntestProdSigns()\n", "buggy_solution": " if (arr.length == 0) { return null }\n let n = 1\n let s = 0\n for (let i = 0; i < arr.length; i++) {\n s += arr[i]\n if (arr[i] == 0) { return 0 }\n if (arr[i] < 0) { n = -n; s -= 2 * arr[i] }\n }\n return s * n * 2\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "prodSigns", "signature": "const prodSigns = (arr)", "docstring": "You are given an array arr of integers and you need to return\nsum of magnitudes of integers multiplied by product of all signs\nof each number in the array, represented by 1, -1 or 0.\nNote: return null for empty arr.\nExample:\n>>> prodSigns([1, 2, 2, -4]) == -9\n>>> prodSigns([0, 1]) == 0\n>>> prodSigns([]) == null", "instruction": "Write a JavaScript function `const prodSigns = (arr)` to solve the following problem:\nYou are given an array arr of integers and you need to return\nsum of magnitudes of integers multiplied by product of all signs\nof each number in the array, represented by 1, -1 or 0.\nNote: return null for empty arr.\nExample:\n>>> prodSigns([1, 2, 2, -4]) == -9\n>>> prodSigns([0, 1]) == 0\n>>> prodSigns([]) == null"} +{"task_id": "JavaScript/129", "prompt": "/*\n Given a grid with N rows and N columns (N >= 2) and a positive integer k, \n each cell of the grid contains a value. Every integer in the range [1, N * N]\n inclusive appears exactly once on the cells of the grid.\n\n You have to find the minimum path of length k in the grid. You can start\n from any cell, and in each step you can move to any of the neighbor cells,\n in other words, you can go to cells which share an edge with you current\n cell.\n Please note that a path of length k means visiting exactly k cells (not\n necessarily distinct).\n You CANNOT go off the grid.\n A path A (of length k) is considered less than a path B (of length k) if\n after making the ordered lists of the values on the cells that A and B go\n through (let's call them lst_A and lst_B), lst_A is lexicographically less\n than lst_B, in other words, there exist an integer index i (1 <= i <= k)\n such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\n lst_A[j] = lst_B[j].\n It is guaranteed that the answer is unique.\n Return an ordered list of the values on the cells that the minimum path go through.\n\n Examples:\n\n Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3\n Output: [1, 2, 1]\n\n Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1\n Output: [1]\n */\nconst minPath = (grid, k) => {\n", "canonical_solution": " let m = 0\n let n = 0\n for (let i = 0; i < grid.length; i++) {\n for (let j = 0; j < grid.length; j++) {\n if (grid[i][j] == 1) {\n m = i;\n n = j;\n break;\n }\n }\n }\n let min = grid.length * grid.length\n if (m > 0 && grid[m - 1][n] < min) { min = grid[m - 1][n] }\n if (n > 0 && grid[m][n - 1] < min) { min = grid[m][n - 1] }\n if (m < grid.length - 1 && grid[m + 1][n] < min) { min = grid[m + 1][n] }\n if (n < grid.length - 1 && grid[m][n + 1] < min) { min = grid[m][n + 1] }\n let p = []\n for (let i = 0; i < k; i++) {\n if (i % 2 == 0) { p.push(1) }\n else { p.push(min) }\n }\n return p\n}\n\n", "test": "const testMinPath = () => {\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9],\n ],\n 3\n )\n ) === JSON.stringify([1, 2, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [5, 9, 3],\n [4, 1, 6],\n [7, 8, 2],\n ],\n 1\n )\n ) === JSON.stringify([1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n ],\n 4\n )\n ) === JSON.stringify([1, 2, 1, 2])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [6, 4, 13, 10],\n [5, 7, 12, 1],\n [3, 16, 11, 15],\n [8, 14, 9, 2],\n ],\n 7\n )\n ) === JSON.stringify([1, 10, 1, 10, 1, 10, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [8, 14, 9, 2],\n [6, 4, 13, 15],\n [5, 7, 1, 12],\n [3, 10, 11, 16],\n ],\n 5\n )\n ) === JSON.stringify([1, 7, 1, 7, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [11, 8, 7, 2],\n [5, 16, 14, 4],\n [9, 3, 15, 6],\n [12, 13, 10, 1],\n ],\n 9\n )\n ) === JSON.stringify([1, 6, 1, 6, 1, 6, 1, 6, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [12, 13, 10, 1],\n [9, 3, 15, 6],\n [5, 16, 14, 4],\n [11, 8, 7, 2],\n ],\n 12\n )\n ) === JSON.stringify([1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [2, 7, 4],\n [3, 1, 5],\n [6, 8, 9],\n ],\n 8\n )\n ) === JSON.stringify([1, 3, 1, 3, 1, 3, 1, 3])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [6, 1, 5],\n [3, 8, 9],\n [2, 7, 4],\n ],\n 8\n )\n ) === JSON.stringify([1, 5, 1, 5, 1, 5, 1, 5])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2],\n [3, 4],\n ],\n 10\n )\n ) === JSON.stringify([1, 2, 1, 2, 1, 2, 1, 2, 1, 2])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 3],\n [4, 2],\n ],\n 10\n )\n ) === JSON.stringify([1, 3, 1, 3, 1, 3, 1, 3, 1, 3])\n )\n}\n\ntestMinPath()\n", "declaration": "\nconst minPath = (grid, k) => {\n", "example_test": "const testMinPath = () => {\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9],\n ],\n 3\n )\n ) === JSON.stringify([1, 2, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [5, 9, 3],\n [4, 1, 6],\n [7, 8, 2],\n ],\n 1\n )\n ) === JSON.stringify([1])\n )\n}\ntestMinPath()\n", "buggy_solution": " let m = 0\n let n = 0\n for (let i = 0; i < grid.length; i++) {\n for (let j = 0; j < grid.length; j++) {\n if (grid[i][j] == 1) {\n m = i;\n n = j;\n break;\n }\n }\n }\n let min = grid.length * grid.length\n if (m > 0 && grid[m - 1][n] < min) { min = grid[m][n] }\n if (n > 0 && grid[m][n - 1] < min) { min = grid[m][n] }\n if (m < grid.length - 1 && grid[m + 1][n] < min) { min = grid[m][n] }\n if (n < grid.length - 1 && grid[m][n + 1] < min) { min = grid[m][n] }\n let p = []\n for (let i = 0; i < k; i++) {\n if (i % 2 == 0) { p.push(1) }\n else { p.push(min) }\n }\n return p\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "minPath", "signature": "const minPath = (grid, k)", "docstring": "Given a grid with N rows and N columns (N >= 2) and a positive integer k,\neach cell of the grid contains a value. Every integer in the range [1, N * N]\ninclusive appears exactly once on the cells of the grid.\nYou have to find the minimum path of length k in the grid. You can start\nfrom any cell, and in each step you can move to any of the neighbor cells,\nin other words, you can go to cells which share an edge with you current\ncell.\nPlease note that a path of length k means visiting exactly k cells (not\nnecessarily distinct).\nYou CANNOT go off the grid.\nA path A (of length k) is considered less than a path B (of length k) if\nafter making the ordered lists of the values on the cells that A and B go\nthrough (let's call them lst_A and lst_B), lst_A is lexicographically less\nthan lst_B, in other words, there exist an integer index i (1 <= i <= k)\nsuch that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\nlst_A[j] = lst_B[j].\nIt is guaranteed that the answer is unique.\nReturn an ordered list of the values on the cells that the minimum path go through.\nExamples:\nInput: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3\nOutput: [1, 2, 1]\nInput: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1\nOutput: [1]", "instruction": "Write a JavaScript function `const minPath = (grid, k)` to solve the following problem:\nGiven a grid with N rows and N columns (N >= 2) and a positive integer k,\neach cell of the grid contains a value. Every integer in the range [1, N * N]\ninclusive appears exactly once on the cells of the grid.\nYou have to find the minimum path of length k in the grid. You can start\nfrom any cell, and in each step you can move to any of the neighbor cells,\nin other words, you can go to cells which share an edge with you current\ncell.\nPlease note that a path of length k means visiting exactly k cells (not\nnecessarily distinct).\nYou CANNOT go off the grid.\nA path A (of length k) is considered less than a path B (of length k) if\nafter making the ordered lists of the values on the cells that A and B go\nthrough (let's call them lst_A and lst_B), lst_A is lexicographically less\nthan lst_B, in other words, there exist an integer index i (1 <= i <= k)\nsuch that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\nlst_A[j] = lst_B[j].\nIt is guaranteed that the answer is unique.\nReturn an ordered list of the values on the cells that the minimum path go through.\nExamples:\nInput: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3\nOutput: [1, 2, 1]\nInput: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1\nOutput: [1]"} +{"task_id": "JavaScript/130", "prompt": "/*Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in \n the last couple centuries. However, what people don't know is Tribonacci sequence.\n Tribonacci sequence is defined by the recurrence:\n tri(1) = 3\n tri(n) = 1 + n / 2, if n is even.\n tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\n For example:\n tri(2) = 1 + (2 / 2) = 2\n tri(4) = 3\n tri(3) = tri(2) + tri(1) + tri(4)\n = 2 + 3 + 3 = 8 \n You are given a non-negative integer number n, you have to a return a list of the \n first n + 1 numbers of the Tribonacci sequence.\n Examples:\n tri(3) = [1, 3, 2, 8]\n */\nconst tri = (n) => {\n", "canonical_solution": " if (n == 0) { return [1] }\n if (n == 1) { return [1, 3] }\n let p = [1, 3]\n for (let i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n p.push(1 + i / 2)\n }\n else {\n p.push(p[i - 2] + p[i - 1] + 1 + (i + 1) / 2)\n }\n }\n return p\n}\n\n", "test": "const testTri = () => {\n console.assert(JSON.stringify(tri(3)) === JSON.stringify([1, 3, 2.0, 8.0]))\n\n console.assert(\n JSON.stringify(tri(4)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0])\n )\n console.assert(\n JSON.stringify(tri(5)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0])\n )\n console.assert(\n JSON.stringify(tri(6)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0])\n )\n console.assert(\n JSON.stringify(tri(7)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0])\n )\n console.assert(\n JSON.stringify(tri(8)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0])\n )\n console.assert(\n JSON.stringify(tri(9)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0])\n )\n console.assert(\n JSON.stringify(tri(20)) ===\n JSON.stringify([\n 1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0, 6.0, 48.0, 7.0, 63.0,\n 8.0, 80.0, 9.0, 99.0, 10.0, 120.0, 11.0,\n ])\n )\n console.assert(JSON.stringify(tri(0)) === JSON.stringify([1]))\n console.assert(JSON.stringify(tri(1)) === JSON.stringify([1, 3]))\n}\n\ntestTri()\n", "declaration": "\nconst tri = (n) => {\n", "example_test": "const testTri = () => {\n console.assert(JSON.stringify(tri(3)) === JSON.stringify([1, 3, 2.0, 8.0]))\n}\ntestTri()\n", "buggy_solution": " if (n == 0) { return [1] }\n if (n == 1) { return [1, 3] }\n let p = [1, 3]\n for (let i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n p.push(1 + i / 2)\n }\n else {\n p.push(p[i - 2] + p[i - 1] + 1 + i + (i + 1) / 2)\n }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "tri", "signature": "const tri = (n)", "docstring": "Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in\nthe last couple centuries. However, what people don't know is Tribonacci sequence.\nTribonacci sequence is defined by the recurrence:\ntri(1) = 3\ntri(n) = 1 + n / 2, if n is even.\ntri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\nFor example:\ntri(2) = 1 + (2 / 2) = 2\ntri(4) = 3\ntri(3) = tri(2) + tri(1) + tri(4)\n= 2 + 3 + 3 = 8\nYou are given a non-negative integer number n, you have to a return a list of the\nfirst n + 1 numbers of the Tribonacci sequence.\nExamples:\ntri(3) = [1, 3, 2, 8]", "instruction": "Write a JavaScript function `const tri = (n)` to solve the following problem:\nEveryone knows Fibonacci sequence, it was studied deeply by mathematicians in\nthe last couple centuries. However, what people don't know is Tribonacci sequence.\nTribonacci sequence is defined by the recurrence:\ntri(1) = 3\ntri(n) = 1 + n / 2, if n is even.\ntri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\nFor example:\ntri(2) = 1 + (2 / 2) = 2\ntri(4) = 3\ntri(3) = tri(2) + tri(1) + tri(4)\n= 2 + 3 + 3 = 8\nYou are given a non-negative integer number n, you have to a return a list of the\nfirst n + 1 numbers of the Tribonacci sequence.\nExamples:\ntri(3) = [1, 3, 2, 8]"} +{"task_id": "JavaScript/131", "prompt": "/*Given a positive integer n, return the product of the odd digits.\n Return 0 if all digits are even.\n For example:\n digits(1) == 1\n digits(4) == 0\n digits(235) == 15\n */\nconst digits = (n) => {\n", "canonical_solution": " let p = 1\n let k = 1\n while (n > 0) {\n let y = n % 10\n if (y % 2 == 1) {\n p *= y; k = 0;\n }\n n = (n - n % 10) / 10\n }\n if (k == 0) { return p }\n return 0\n}\n\n", "test": "const testDigits = () => {\n console.assert(digits(5) === 5)\n console.assert(digits(54) === 5)\n console.assert(digits(120) === 1)\n console.assert(digits(5014) === 5)\n console.assert(digits(98765) === 315)\n console.assert(digits(5576543) === 2625)\n console.assert(digits(2468) === 0)\n}\n\ntestDigits()\n", "declaration": "\nconst digits = (n) => {\n", "example_test": "const testDigits = () => {\n console.assert(digits(1) === 1)\n console.assert(digits(4) === 0)\n console.assert(digits(235) === 15)\n}\ntestDigits()\n", "buggy_solution": " let p = 1\n let k = 1\n while (n > 0) {\n let y = n % 10\n if (y % 2 == 1) {\n p *= p*y; k = 0;\n }\n n = (n - n % 10) / 10\n }\n if (k == 0) { return p }\n return 0\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "digits", "signature": "const digits = (n)", "docstring": "Given a positive integer n, return the product of the odd digits.\nReturn 0 if all digits are even.\nFor example:\ndigits(1) == 1\ndigits(4) == 0\ndigits(235) == 15", "instruction": "Write a JavaScript function `const digits = (n)` to solve the following problem:\nGiven a positive integer n, return the product of the odd digits.\nReturn 0 if all digits are even.\nFor example:\ndigits(1) == 1\ndigits(4) == 0\ndigits(235) == 15"} +{"task_id": "JavaScript/132", "prompt": "/*\n Create a function that takes a string as input which contains only square brackets.\n The function should return true if and only if there is a valid subsequence of brackets\n where at least one bracket in the subsequence is nested.\n isNested('[[]]') \u279e true\n isNested('[]]]]]]][[[[[]') \u279e false\n isNested('[][]') \u279e false\n isNested('[]') \u279e false\n isNested('[[][]]') \u279e true\n isNested('[[]][[') \u279e true\n */\nconst isNested = (string) => {\n", "canonical_solution": " let opening_bracket_index = []\n let closing_bracket_index1 = []\n for (let i = 0; i < string.length; i++) {\n if (string[i] == '[') {\n opening_bracket_index.push(i)\n }\n else {\n closing_bracket_index1.push(i)\n }\n }\n let closing_bracket_index = []\n for (let i = 0; i < closing_bracket_index1.length; i++) {\n closing_bracket_index.push(closing_bracket_index1[closing_bracket_index1.length - i - 1])\n }\n let cnt = 0\n let i = 0\n let l = closing_bracket_index.length\n for (let k = 0; k < opening_bracket_index.length; k++) {\n if (i < l && opening_bracket_index[k] < closing_bracket_index[i]) {\n cnt += 1;\n i += 1;\n }\n }\n return cnt >= 2\n}\n\n", "test": "const testIsNested = () => {\n console.assert(isNested('[[]]') === true)\n console.assert(isNested('[]]]]]]][[[[[]') === false)\n console.assert(isNested('[][]') === false)\n console.assert(isNested('[]') === false)\n console.assert(isNested('[[[[]]]]') === true)\n console.assert(isNested('[]]]]]]]]]]') === false)\n console.assert(isNested('[][][[]]') === true)\n console.assert(isNested('[[]') === false)\n console.assert(isNested('[]]') === false)\n console.assert(isNested('[[]][[') === true)\n console.assert(isNested('[[][]]') === true)\n console.assert(isNested('') === false)\n console.assert(isNested('[[[[[[[[') === false)\n console.assert(isNested(']]]]]]]]') === false)\n}\n\ntestIsNested()\n", "declaration": "\nconst isNested = (string) => {\n", "example_test": "const testIsNested = () => {\n console.assert(isNested('[[]]') === true)\n console.assert(isNested('[]]]]]]][[[[[]') === false)\n console.assert(isNested('[][]') === false)\n console.assert(isNested('[]') === false)\n console.assert(isNested('[[]][[') === true)\n console.assert(isNested('[[][]]') === true)\n}\ntestIsNested()\n", "buggy_solution": " let opening_bracket_index = []\n let closing_bracket_index1 = []\n for (let i = 0; i < string.length; i++) {\n if (string[i] == '(') {\n opening_bracket_index.push(i)\n }\n else {\n closing_bracket_index1.push(i)\n }\n }\n let closing_bracket_index = []\n for (let i = 0; i < closing_bracket_index1.length; i++) {\n closing_bracket_index.push(closing_bracket_index1[closing_bracket_index1.length - i - 1])\n }\n let cnt = 0\n let i = 0\n let l = closing_bracket_index.length\n for (let k = 0; k < opening_bracket_index.length; k++) {\n if (i < l && opening_bracket_index[k] < closing_bracket_index[i]) {\n cnt += 1;\n i += 1;\n }\n }\n return cnt >= 2\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "isNested", "signature": "const isNested = (string)", "docstring": "Create a function that takes a string as input which contains only square brackets.\nThe function should return true if and only if there is a valid subsequence of brackets\nwhere at least one bracket in the subsequence is nested.\nisNested('[[]]') \u279e true\nisNested('[]]]]]]][[[[[]') \u279e false\nisNested('[][]') \u279e false\nisNested('[]') \u279e false\nisNested('[[][]]') \u279e true\nisNested('[[]][[') \u279e true", "instruction": "Write a JavaScript function `const isNested = (string)` to solve the following problem:\nCreate a function that takes a string as input which contains only square brackets.\nThe function should return true if and only if there is a valid subsequence of brackets\nwhere at least one bracket in the subsequence is nested.\nisNested('[[]]') \u279e true\nisNested('[]]]]]]][[[[[]') \u279e false\nisNested('[][]') \u279e false\nisNested('[]') \u279e false\nisNested('[[][]]') \u279e true\nisNested('[[]][[') \u279e true"} +{"task_id": "JavaScript/133", "prompt": "/*You are given a list of numbers.\n You need to return the sum of squared numbers in the given list,\n round each element in the list to the upper int(Ceiling) first.\n Examples:\n For lst = [1,2,3] the output should be 14\n For lst = [1,4,9] the output should be 98\n For lst = [1,3,5,7] the output should be 84\n For lst = [1.4,4.2,0] the output should be 29\n For lst = [-2.4,1,1] the output should be 6\n */\nconst sumSquares = (lst) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n let y = lst[i]\n if (y % 1 != 0) {\n if (y > 0) { y = y - y % 1 + 1 }\n else { y = -y; y = y - y % 1 }\n }\n p += y * y\n }\n return p\n}\n\n", "test": "const testSumSquares = () => {\n console.assert(sumSquares([1, 2, 3]) === 14)\n console.assert(sumSquares([1.0, 2, 3]) === 14)\n console.assert(sumSquares([1, 3, 5, 7]) === 84)\n console.assert(sumSquares([1.4, 4.2, 0]) === 29)\n console.assert(sumSquares([-2.4, 1, 1]) === 6)\n\n console.assert(sumSquares([100, 1, 15, 2]) === 10230)\n console.assert(sumSquares([10000, 10000]) === 200000000)\n console.assert(sumSquares([-1.4, 4.6, 6.3]) === 75)\n console.assert(sumSquares([-1.4, 17.9, 18.9, 19.9]) === 1086)\n\n console.assert(sumSquares([0]) === 0)\n console.assert(sumSquares([-1]) === 1)\n console.assert(sumSquares([-1, 1, 0]) === 2)\n}\n\ntestSumSquares()\n", "declaration": "\nconst sumSquares = (lst) => {\n", "example_test": "const testSumSquares = () => {\n console.assert(sumSquares([1, 2, 3]) === 14)\n console.assert(sumSquares([1, 4, 9]) === 98)\n console.assert(sumSquares([1, 3, 5, 7]) === 84)\n console.assert(sumSquares([1.4, 4.2, 0]) === 29)\n console.assert(sumSquares([-2.4, 1, 1]) === 6)\n}\ntestSumSquares()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n let y = lst[i]\n if (y % 1 != 0) {\n if (y > 0) { y = y - y % 1 + 1 }\n else { y = -y; y = y - y % 1 }\n }\n p += y * 2\n }\n return p\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "sumSquares", "signature": "const sumSquares = (lst)", "docstring": "You are given a list of numbers.\nYou need to return the sum of squared numbers in the given list,\nround each element in the list to the upper int(Ceiling) first.\nExamples:\nFor lst = [1,2,3] the output should be 14\nFor lst = [1,4,9] the output should be 98\nFor lst = [1,3,5,7] the output should be 84\nFor lst = [1.4,4.2,0] the output should be 29\nFor lst = [-2.4,1,1] the output should be 6", "instruction": "Write a JavaScript function `const sumSquares = (lst)` to solve the following problem:\nYou are given a list of numbers.\nYou need to return the sum of squared numbers in the given list,\nround each element in the list to the upper int(Ceiling) first.\nExamples:\nFor lst = [1,2,3] the output should be 14\nFor lst = [1,4,9] the output should be 98\nFor lst = [1,3,5,7] the output should be 84\nFor lst = [1.4,4.2,0] the output should be 29\nFor lst = [-2.4,1,1] the output should be 6"} +{"task_id": "JavaScript/134", "prompt": "/* Create a function that returns true if the last character\n of a given string is an alphabetical character and is not\n a part of a word, and false otherwise.\n Note: \"word\" is a group of characters separated by space.\n Examples:\n checkIfLastCharIsALetter(\"apple pie\") \u279e false\n checkIfLastCharIsALetter(\"apple pi e\") \u279e true\n checkIfLastCharIsALetter(\"apple pi e \") \u279e false\n checkIfLastCharIsALetter(\"\") \u279e false\n */\nconst checkIfLastCharIsALetter = (txt) => {\n", "canonical_solution": " let len = txt.length\n if (len == 0) { return false }\n let y = txt[len - 1].charCodeAt()\n if (len == 1) {\n if ((y >= 65 && y <= 90) || (y >= 97 && y <= 122)) { return true }\n return false\n }\n if (txt[len - 2] == ' ' && ((y >= 65 && y <= 90) || (y >= 97 && y <= 122))) { return true }\n return false\n}\n\n", "test": "const testCheckIfLastCharIsALetter = () => {\n console.assert(checkIfLastCharIsALetter('apple') === false)\n console.assert(checkIfLastCharIsALetter('apple pi e') === true)\n console.assert(checkIfLastCharIsALetter('eeeee') === false)\n console.assert(checkIfLastCharIsALetter('A') === true)\n console.assert(checkIfLastCharIsALetter('Pumpkin pie ') === false)\n console.assert(checkIfLastCharIsALetter('Pumpkin pie 1') === false)\n console.assert(checkIfLastCharIsALetter('') === false)\n console.assert(checkIfLastCharIsALetter('eeeee e ') === false)\n console.assert(checkIfLastCharIsALetter('apple pie') === false)\n console.assert(checkIfLastCharIsALetter('apple pi e ') === false)\n}\n\ntestCheckIfLastCharIsALetter()\n", "declaration": "\nconst checkIfLastCharIsALetter = (txt) => {\n", "example_test": "const testCheckIfLastCharIsALetter = () => {\n console.assert(checkIfLastCharIsALetter('apple pi e') === true)\n console.assert(checkIfLastCharIsALetter('') === false)\n console.assert(checkIfLastCharIsALetter('apple pie') === false)\n console.assert(checkIfLastCharIsALetter('apple pi e ') === false)\n}\ntestCheckIfLastCharIsALetter()\n", "buggy_solution": " let len = txt.length\n if (len == 0) { return false }\n let y = txt[len - 1].charCodeAt()\n if (len == 1) {\n if ((y >= 0 && y <= 22) || (y >= 30 && y <= 54)) { return true }\n return false\n }\n if (txt[len - 2] == ' ' && ((y >= 150 && y <= 200) || (y >= 250 && y <= 300))) { return true }\n return false\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "checkIfLastCharIsALetter", "signature": "const checkIfLastCharIsALetter = (txt)", "docstring": "Create a function that returns true if the last character\nof a given string is an alphabetical character and is not\na part of a word, and false otherwise.\nNote: \"word\" is a group of characters separated by space.\nExamples:\ncheckIfLastCharIsALetter(\"apple pie\") \u279e false\ncheckIfLastCharIsALetter(\"apple pi e\") \u279e true\ncheckIfLastCharIsALetter(\"apple pi e \") \u279e false\ncheckIfLastCharIsALetter(\"\") \u279e false", "instruction": "Write a JavaScript function `const checkIfLastCharIsALetter = (txt)` to solve the following problem:\nCreate a function that returns true if the last character\nof a given string is an alphabetical character and is not\na part of a word, and false otherwise.\nNote: \"word\" is a group of characters separated by space.\nExamples:\ncheckIfLastCharIsALetter(\"apple pie\") \u279e false\ncheckIfLastCharIsALetter(\"apple pi e\") \u279e true\ncheckIfLastCharIsALetter(\"apple pi e \") \u279e false\ncheckIfLastCharIsALetter(\"\") \u279e false"} +{"task_id": "JavaScript/135", "prompt": "/*Create a function which returns the largest index of an element which\n is not greater than or equal to the element immediately preceding it. If\n no such element exists then return -1. The given array will not contain\n duplicate values.\n\n Examples:\n canArrange([1,2,4,3,5]) = 3\n canArrange([1,2,3]) = -1\n */\nconst canArrange = (arr) => {\n", "canonical_solution": " if (arr.length == 0) { return -1 }\n for (let i = arr.length - 1; i > 0; i--) {\n if (arr[i] < arr[i - 1]) { return i }\n }\n return -1\n}\n\n", "test": "const testCanArrange = () => {\n console.assert(canArrange([1, 2, 4, 3, 5]) === 3)\n console.assert(canArrange([1, 2, 4, 5]) === -1)\n console.assert(canArrange([1, 4, 2, 5, 6, 7, 8, 9, 10]) === 2)\n console.assert(canArrange([4, 8, 5, 7, 3]) === 4)\n console.assert(canArrange([]) === -1)\n}\n\ntestCanArrange()\n", "declaration": "\nconst canArrange = (arr) => {\n", "example_test": "const testCanArrange = () => {\n console.assert(canArrange([1, 2, 4, 3, 5]) === 3)\n console.assert(canArrange([1, 2, 3]) === -1)\n}\ntestCanArrange()\n", "buggy_solution": " if (arr.length == 0) { return -1 }\n for (let i = arr.length - 1; i > 0; i--) {\n if (arr[i] < arr[i - 1]) { return i + arr[i] }\n }\n return -1\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "canArrange", "signature": "const canArrange = (arr)", "docstring": "Create a function which returns the largest index of an element which\nis not greater than or equal to the element immediately preceding it. If\nno such element exists then return -1. The given array will not contain\nduplicate values.\nExamples:\ncanArrange([1,2,4,3,5]) = 3\ncanArrange([1,2,3]) = -1", "instruction": "Write a JavaScript function `const canArrange = (arr)` to solve the following problem:\nCreate a function which returns the largest index of an element which\nis not greater than or equal to the element immediately preceding it. If\nno such element exists then return -1. The given array will not contain\nduplicate values.\nExamples:\ncanArrange([1,2,4,3,5]) = 3\ncanArrange([1,2,3]) = -1"} +{"task_id": "JavaScript/136", "prompt": "/* Create a function that returns a tuple (a, b), where 'a' is\n the largest of negative integers, and 'b' is the smallest\n of positive integers in a list.\n If there is no negative or positive integers, return them as null.\n Examples:\n largestSmallestIntegers([2, 4, 1, 3, 5, 7]) == (null, 1)\n largestSmallestIntegers([]) == (null, null)\n largestSmallestIntegers([0]) == (null, null)\n */\nconst largestSmallestIntegers = (lst) => {\n", "canonical_solution": " let a = Infinity\n let b = -Infinity\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] > 0 && lst[i] < a) { a = lst[i] }\n if (lst[i] < 0 && lst[i] > b) { b = lst[i] }\n }\n if (a == Infinity) { a = null }\n if (b == -Infinity) { b = null }\n return (b, a)\n}\n\n", "test": "const testLargestSmallestIntegers = () => {\n console.assert(\n JSON.stringify(largestSmallestIntegers([2, 4, 1, 3, 5, 7])) ===\n JSON.stringify((null, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([2, 4, 1, 3, 5, 7, 0])) ===\n JSON.stringify((null, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([1, 3, 2, 4, 5, 6, -2])) ===\n JSON.stringify((-2, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([4, 5, 3, 6, 2, 7, -7])) ===\n JSON.stringify((-7, 2))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([7, 3, 8, 4, 9, 2, 5, -9])) ===\n JSON.stringify((-9, 2))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([])) === JSON.stringify((null, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([0])) ===\n JSON.stringify((null, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-1, -3, -5, -6])) ===\n JSON.stringify((-1, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-1, -3, -5, -6, 0])) ===\n JSON.stringify((-1, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-6, -4, -4, -3, 1])) ===\n JSON.stringify((-3, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-6, -4, -4, -3, -100, 1])) ===\n JSON.stringify((-3, 1))\n )\n}\n\ntestLargestSmallestIntegers()\n", "declaration": "\nconst largestSmallestIntegers = (lst) => {\n", "example_test": "const testLargestSmallestIntegers = () => {\n console.assert(\n JSON.stringify(largestSmallestIntegers([2, 4, 1, 3, 5, 7])) ===\n JSON.stringify((null, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([])) === JSON.stringify((null, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([0])) ===\n JSON.stringify((null, null))\n )\n}\ntestLargestSmallestIntegers()\n", "buggy_solution": " let a = Infinity\n let b = -Infinity\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] > 0 && lst[i] < a) { a = lst[i] }\n if (lst[i] < 0 && lst[i] > b) { b = lst[i] }\n if (lst[i] < a) { b = a }\n if (lst[i] < b) { a = b }\n }\n if (a == Infinity) { a = null }\n if (b == -Infinity) { b = null }\n return (b, a)\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "largestSmallestIntegers", "signature": "const largestSmallestIntegers = (lst)", "docstring": "Create a function that returns a tuple (a, b), where 'a' is\nthe largest of negative integers, and 'b' is the smallest\nof positive integers in a list.\nIf there is no negative or positive integers, return them as null.\nExamples:\nlargestSmallestIntegers([2, 4, 1, 3, 5, 7]) == (null, 1)\nlargestSmallestIntegers([]) == (null, null)\nlargestSmallestIntegers([0]) == (null, null)", "instruction": "Write a JavaScript function `const largestSmallestIntegers = (lst)` to solve the following problem:\nCreate a function that returns a tuple (a, b), where 'a' is\nthe largest of negative integers, and 'b' is the smallest\nof positive integers in a list.\nIf there is no negative or positive integers, return them as null.\nExamples:\nlargestSmallestIntegers([2, 4, 1, 3, 5, 7]) == (null, 1)\nlargestSmallestIntegers([]) == (null, null)\nlargestSmallestIntegers([0]) == (null, null)"} +{"task_id": "JavaScript/137", "prompt": "/*\n Create a function that takes integers, floats, or strings representing\n real numbers, and returns the larger variable in its given variable type.\n Return null if the values are equal.\n Note: If a real number is represented as a string, the floating point might be . or ,\n\n compareOne(1, 2.5) \u279e 2.5\n compareOne(1, \"2,3\") \u279e \"2,3\"\n compareOne(\"5,1\", \"6\") \u279e \"6\"\n compareOne(\"1\", 1) \u279e null\n */\nconst compareOne = (a, b) => {\n", "canonical_solution": " let aa = Number(a)\n if (typeof a == 'string') { aa = Number(a.replace(',', '.')) }\n let bb = Number(b)\n if (typeof b == 'string') { bb = Number(b.replace(',', '.')) }\n if (aa > bb) { return a }\n if (aa < bb) { return b }\n return null\n}\n\n", "test": "const testCompareOne = () => {\n console.assert(compareOne(1, 2) === 2)\n console.assert(compareOne(1, 2.5) === 2.5)\n console.assert(compareOne(2, 3) === 3)\n console.assert(compareOne(5, 6) === 6)\n console.assert(compareOne(1, '2,3') === '2,3')\n console.assert(compareOne('5,1', '6') === '6')\n console.assert(compareOne('1', '2') === '2')\n console.assert(compareOne('1', 1) === null)\n}\n\ntestCompareOne()\n", "declaration": "\nconst compareOne = (a, b) => {\n", "example_test": "const testCompareOne = () => {\n console.assert(compareOne(1, 2.5) === 2.5)\n console.assert(compareOne(1, '2,3') === '2,3')\n console.assert(compareOne('5,1', '6') === '6')\n console.assert(compareOne('1', 1) === null)\n}\ntestCompareOne()\n", "buggy_solution": " let aa = Number(a)\n if (typeof a == 'string') { aa = Number(a.replace(',', '.').replace('.', ',')) }\n let bb = Number(b)\n if (typeof b == 'string') { bb = Number(b.replace(',', '.')) }\n if (aa > bb) { return a }\n if (aa < bb) { return b }\n return null\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "compareOne", "signature": "const compareOne = (a, b)", "docstring": "Create a function that takes integers, floats, or strings representing\nreal numbers, and returns the larger variable in its given variable type.\nReturn null if the values are equal.\nNote: If a real number is represented as a string, the floating point might be . or ,\ncompareOne(1, 2.5) \u279e 2.5\ncompareOne(1, \"2,3\") \u279e \"2,3\"\ncompareOne(\"5,1\", \"6\") \u279e \"6\"\ncompareOne(\"1\", 1) \u279e null", "instruction": "Write a JavaScript function `const compareOne = (a, b)` to solve the following problem:\nCreate a function that takes integers, floats, or strings representing\nreal numbers, and returns the larger variable in its given variable type.\nReturn null if the values are equal.\nNote: If a real number is represented as a string, the floating point might be . or ,\ncompareOne(1, 2.5) \u279e 2.5\ncompareOne(1, \"2,3\") \u279e \"2,3\"\ncompareOne(\"5,1\", \"6\") \u279e \"6\"\ncompareOne(\"1\", 1) \u279e null"} +{"task_id": "JavaScript/138", "prompt": "/*Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers\n Example\n isEqualToSumEven(4) == false\n isEqualToSumEven(6) == false\n isEqualToSumEven(8) == true\n */\nconst isEqualToSumEven = (n) => {\n", "canonical_solution": " return (n >= 8 && n % 2 == 0)\n}\n\n", "test": "const testIsEqualToSumEven = () => {\n console.assert(isEqualToSumEven(4) === false)\n console.assert(isEqualToSumEven(6) === false)\n console.assert(isEqualToSumEven(8) === true)\n console.assert(isEqualToSumEven(10) === true)\n console.assert(isEqualToSumEven(11) === false)\n console.assert(isEqualToSumEven(12) === true)\n console.assert(isEqualToSumEven(13) === false)\n console.assert(isEqualToSumEven(16) === true)\n}\n\ntestIsEqualToSumEven()\n", "declaration": "\nconst isEqualToSumEven = (n) => {\n", "example_test": "const testIsEqualToSumEven = () => {\n console.assert(isEqualToSumEven(4) === false)\n console.assert(isEqualToSumEven(6) === false)\n console.assert(isEqualToSumEven(8) === true)\n}\ntestIsEqualToSumEven()\n", "buggy_solution": " return (n >= 8 && n <= 8 && n % 2 == 0)\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "isEqualToSumEven", "signature": "const isEqualToSumEven = (n)", "docstring": "Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers\nExample\nisEqualToSumEven(4) == false\nisEqualToSumEven(6) == false\nisEqualToSumEven(8) == true", "instruction": "Write a JavaScript function `const isEqualToSumEven = (n)` to solve the following problem:\nEvaluate whether the given number n can be written as the sum of exactly 4 positive even numbers\nExample\nisEqualToSumEven(4) == false\nisEqualToSumEven(6) == false\nisEqualToSumEven(8) == true"} +{"task_id": "JavaScript/139", "prompt": "/*The Brazilian factorial is defined as:\n brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\n where n > 0\n\n For example:\n >>> specialFactorial(4)\n 288\n\n The function will receive an integer as input and should return the special\n factorial of this integer.\n */\nconst specialFactorial = (n) => {\n", "canonical_solution": " let p = 1;\n let t = 1;\n while (n > 1) {\n let y = p;\n while (y > 0) {\n y--;\n t *= n;\n }\n p++;\n n--;\n }\n return t\n}\n\n", "test": "const testSpecialFactorial = () => {\n console.assert(specialFactorial(4) === 288)\n console.assert(specialFactorial(5) === 34560)\n console.assert(specialFactorial(7) === 125411328000)\n console.assert(specialFactorial(1) === 1)\n}\n\ntestSpecialFactorial()\n", "declaration": "\nconst specialFactorial = (n) => {\n", "example_test": "const testSpecialFactorial = () => {\n console.assert(specialFactorial(4) === 288)\n}\ntestSpecialFactorial()\n", "buggy_solution": " let p = 1;\n let t = 1;\n while (n > 1) {\n let y = p;\n while (y > 0) {\n y--;\n n *= y;\n t *= n;\n }\n p++;\n p++;\n n--;\n }\n return t\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "specialFactorial", "signature": "const specialFactorial = (n)", "docstring": "The Brazilian factorial is defined as:\nbrazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\nwhere n > 0\nFor example:\n>>> specialFactorial(4)\n288\nThe function will receive an integer as input and should return the special\nfactorial of this integer.", "instruction": "Write a JavaScript function `const specialFactorial = (n)` to solve the following problem:\nThe Brazilian factorial is defined as:\nbrazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\nwhere n > 0\nFor example:\n>>> specialFactorial(4)\n288\nThe function will receive an integer as input and should return the special\nfactorial of this integer."} +{"task_id": "JavaScript/140", "prompt": "/*\n Given a string text, replace all spaces in it with underscores, \n and if a string has more than 2 consecutive spaces, \n then replace all consecutive spaces with - \n \n fixSpaces(\"Example\") == \"Example\"\n fixSpaces(\"Example 1\") == \"Example_1\"\n fixSpaces(\" Example 2\") == \"_Example_2\"\n fixSpaces(\" Example 3\") == \"_Example-3\"\n */\nconst fixSpaces = (text) => {\n", "canonical_solution": " let t = ''\n let c = 0\n for (let i = 0; i < text.length; i++) {\n if (text[i] == ' ') { c++ }\n else if (c > 0) {\n if (c == 1) { t += '_' }\n if (c == 2) { t += '__' }\n if (c > 2) { t += '-' }\n t += text[i]\n c = 0;\n } else {\n t += text[i]\n }\n }\n if (c == 1) { t += '_' }\n if (c == 2) { t += '__' }\n if (c > 2) { t += '-' }\n return t\n}\n\n", "test": "const testFixSpaces = () => {\n console.assert(fixSpaces('Example') === 'Example')\n console.assert(fixSpaces('Mudasir Hanif ') === 'Mudasir_Hanif_')\n console.assert(\n fixSpaces('Yellow Yellow Dirty Fellow') === 'Yellow_Yellow__Dirty__Fellow'\n )\n console.assert(fixSpaces('Exa mple') === 'Exa-mple')\n console.assert(fixSpaces(' Exa 1 2 2 mple') === '-Exa_1_2_2_mple')\n}\n\ntestFixSpaces()\n", "declaration": "\nconst fixSpaces = (text) => {\n", "example_test": "const testFixSpaces = () => {\n console.assert(fixSpaces('Example') === 'Example')\n console.assert(fixSpaces('Example 1') === 'Example_1')\n console.assert(\n fixSpaces(' Example 2') === '_Example_2'\n )\n console.assert(fixSpaces(' Example 3') === '_Example-3')\n}\ntestFixSpaces()\n", "buggy_solution": " let t = ''\n let c = 0\n for (let i = 0; i < text.length; i++) {\n if (text[i] == ' ') { c++ }\n else if (c > 0) {\n if (c == 1) { t += '_' }\n if (c == 2) { t += '___' }\n if (c > 2) { t += '--' }\n t += text[i]\n c = 0;\n } else {\n t += text[i]\n }\n }\n if (c == 1) { t += '__' }\n if (c == 2) { t += '___' }\n if (c > 2) { t += '-' }\n return t\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "fixSpaces", "signature": "const fixSpaces = (text)", "docstring": "Given a string text, replace all spaces in it with underscores,\nand if a string has more than 2 consecutive spaces,\nthen replace all consecutive spaces with -\nfixSpaces(\"Example\") == \"Example\"\nfixSpaces(\"Example 1\") == \"Example_1\"\nfixSpaces(\" Example 2\") == \"_Example_2\"\nfixSpaces(\" Example 3\") == \"_Example-3\"", "instruction": "Write a JavaScript function `const fixSpaces = (text)` to solve the following problem:\nGiven a string text, replace all spaces in it with underscores,\nand if a string has more than 2 consecutive spaces,\nthen replace all consecutive spaces with -\nfixSpaces(\"Example\") == \"Example\"\nfixSpaces(\"Example 1\") == \"Example_1\"\nfixSpaces(\" Example 2\") == \"_Example_2\"\nfixSpaces(\" Example 3\") == \"_Example-3\""} +{"task_id": "JavaScript/141", "prompt": "/*Create a function which takes a string representing a file's name, and returns\n 'Yes' if the the file's name is valid, and returns 'No' otherwise.\n A file's name is considered to be valid if and only if all the following conditions \n are met:\n - There should not be more than three digits ('0'-'9') in the file's name.\n - The file's name contains exactly one dot '.'\n - The substring before the dot should not be empty, and it starts with a letter from \n the latin alphapet ('a'-'z' and 'A'-'Z').\n - The substring after the dot should be one of these: ['txt', 'exe', 'dll']\n Examples:\n fileNameCheck(\"example.txt\") # => 'Yes'\n fileNameCheck(\"1example.dll\") # => 'No' (the name should start with a latin alphapet letter)\n */\nconst fileNameCheck = (file_name) => {\n", "canonical_solution": " let t = file_name.split(/\\./)\n if (t.length != 2) { return 'No' }\n if (t[1] != 'txt' && t[1] != 'dll' && t[1] != 'exe') { return 'No' }\n if (t[0] == '') { return 'No' }\n let a = t[0][0].charCodeAt()\n if (!((a >= 65 && a <= 90) || (a >= 97 && a <= 122))) { return 'No' }\n let y = 0\n for (let i = 1; i < t[0].length; i++) {\n if (t[0][i].charCodeAt() >= 48 && t[0][i].charCodeAt() <= 57) { y++ }\n if (y > 3) { return 'No' }\n }\n return 'Yes'\n}\n\n", "test": "const testFileNameCheck = () => {\n console.assert(fileNameCheck('example.txt') === 'Yes')\n console.assert(fileNameCheck('1example.dll') === 'No')\n console.assert(fileNameCheck('s1sdf3.asd') === 'No')\n console.assert(fileNameCheck('K.dll') === 'Yes')\n console.assert(fileNameCheck('MY16FILE3.exe') === 'Yes')\n console.assert(fileNameCheck('His12FILE94.exe') === 'No')\n console.assert(fileNameCheck('_Y.txt') === 'No')\n console.assert(fileNameCheck('?aREYA.exe') === 'No')\n console.assert(fileNameCheck('/this_is_valid.dll') === 'No')\n console.assert(fileNameCheck('this_is_valid.wow') === 'No')\n console.assert(fileNameCheck('this_is_valid.txt') === 'Yes')\n console.assert(fileNameCheck('this_is_valid.txtexe') === 'No')\n console.assert(fileNameCheck('#this2_i4s_5valid.ten') === 'No')\n console.assert(fileNameCheck('@this1_is6_valid.exe') === 'No')\n console.assert(fileNameCheck('this_is_12valid.6exe4.txt') === 'No')\n console.assert(fileNameCheck('all.exe.txt') === 'No')\n console.assert(fileNameCheck('I563_No.exe') === 'Yes')\n console.assert(fileNameCheck('Is3youfault.txt') === 'Yes')\n console.assert(fileNameCheck('no_one#knows.dll') === 'Yes')\n console.assert(fileNameCheck('1I563_Yes3.exe') === 'No')\n console.assert(fileNameCheck('I563_Yes3.txtt') === 'No')\n console.assert(fileNameCheck('final..txt') === 'No')\n console.assert(fileNameCheck('final132') === 'No')\n console.assert(fileNameCheck('_f4indsartal132.') === 'No')\n console.assert(fileNameCheck('.txt') === 'No')\n console.assert(fileNameCheck('s.') === 'No')\n}\n\ntestFileNameCheck()\n", "declaration": "\nconst fileNameCheck = (file_name) => {\n", "example_test": "const testFileNameCheck = () => {\n console.assert(fileNameCheck('example.txt') === 'Yes')\n console.assert(fileNameCheck('1example.dll') === 'No')\n}\ntestFileNameCheck()\n", "buggy_solution": " let t = file_name.split(/\\./)\n if (t.length != 2) { return 'No' }\n if (t[0] == '') { return 'No' }\n let a = t[0][0].charCodeAt()\n if (!((a >= 65 && a <= 90) || (a >= 97 && a <= 122))) { return 'No' }\n let y = 0\n for (let i = 1; i < t[0].length; i++) {\n if (t[0][i].charCodeAt() >= 48 && t[0][i].charCodeAt() <= 57) { y++ }\n if (y > 3) { return 'No' }\n }\n return 'Yes'\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "fileNameCheck", "signature": "const fileNameCheck = (file_name)", "docstring": "Create a function which takes a string representing a file's name, and returns\n'Yes' if the the file's name is valid, and returns 'No' otherwise.\nA file's name is considered to be valid if and only if all the following conditions\nare met:\n- There should not be more than three digits ('0'-'9') in the file's name.\n- The file's name contains exactly one dot '.'\n- The substring before the dot should not be empty, and it starts with a letter from\nthe latin alphapet ('a'-'z' and 'A'-'Z').\n- The substring after the dot should be one of these: ['txt', 'exe', 'dll']\nExamples:\nfileNameCheck(\"example.txt\") # => 'Yes'\nfileNameCheck(\"1example.dll\") # => 'No' (the name should start with a latin alphapet letter)", "instruction": "Write a JavaScript function `const fileNameCheck = (file_name)` to solve the following problem:\nCreate a function which takes a string representing a file's name, and returns\n'Yes' if the the file's name is valid, and returns 'No' otherwise.\nA file's name is considered to be valid if and only if all the following conditions\nare met:\n- There should not be more than three digits ('0'-'9') in the file's name.\n- The file's name contains exactly one dot '.'\n- The substring before the dot should not be empty, and it starts with a letter from\nthe latin alphapet ('a'-'z' and 'A'-'Z').\n- The substring after the dot should be one of these: ['txt', 'exe', 'dll']\nExamples:\nfileNameCheck(\"example.txt\") # => 'Yes'\nfileNameCheck(\"1example.dll\") # => 'No' (the name should start with a latin alphapet letter)"} +{"task_id": "JavaScript/142", "prompt": "/*\"\n This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a \n multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not \n change the entries in the list whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries. \n \n Examples:\n For lst = [1,2,3] the output should be 6\n For lst = [] the output should be 0\n For lst = [-1,-5,2,-1,-5] the output should be -126\n */\nconst sumSquares = (lst) => {\n", "canonical_solution": " let y = 0\n for (let i = 0; i < lst.length; i++) {\n if (i % 3 == 0) { y += lst[i] * lst[i] }\n else if (i % 4 == 0) { y += lst[i] * lst[i] * lst[i] }\n else { y += lst[i] }\n }\n return y\n}\n\n", "test": "const testSumSquares = () => {\n console.assert(sumSquares([1, 2, 3]) === 6)\n console.assert(sumSquares([1, 4, 9]) === 14)\n console.assert(sumSquares([]) === 0)\n console.assert(sumSquares([1, 1, 1, 1, 1, 1, 1, 1, 1]) === 9)\n console.assert(sumSquares([-1, -1, -1, -1, -1, -1, -1, -1, -1]) === -3)\n console.assert(sumSquares([0]) === 0)\n console.assert(sumSquares([-1, -5, 2, -1, -5]) === -126)\n console.assert(sumSquares([-56, -99, 1, 0, -2]) === 3030)\n console.assert(sumSquares([-1, 0, 0, 0, 0, 0, 0, 0, -1]) === 0)\n console.assert(\n sumSquares([\n -16, -9, -2, 36, 36, 26, -20, 25, -40, 20, -4, 12, -26, 35, 37,\n ]) === -14196\n )\n console.assert(\n sumSquares([\n -1, -3, 17, -1, -15, 13, -1, 14, -14, -12, -5, 14, -14, 6, 13, 11, 16, 16,\n 4, 10,\n ]) === -1448\n )\n}\n\ntestSumSquares()\n", "declaration": "\nconst sumSquares = (lst) => {\n", "example_test": "const testSumSquares = () => {\n console.assert(sumSquares([1, 2, 3]) === 6)\n console.assert(sumSquares([]) === 0)\n console.assert(sumSquares([-1, -5, 2, -1, -5]) === -126)\n}\ntestSumSquares()\n", "buggy_solution": " let y = 0\n for (let i = 0; i < lst.length; i++) {\n if (i % 3 == 0) { y += lst[i] * lst[i] }\n else { y += lst[i] }\n }\n return y\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sumSquares", "signature": "const sumSquares = (lst)", "docstring": "\"\nThis function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a\nmultiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not\nchange the entries in the list whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries.\nExamples:\nFor lst = [1,2,3] the output should be 6\nFor lst = [] the output should be 0\nFor lst = [-1,-5,2,-1,-5] the output should be -126", "instruction": "Write a JavaScript function `const sumSquares = (lst)` to solve the following problem:\n\"\nThis function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a\nmultiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not\nchange the entries in the list whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries.\nExamples:\nFor lst = [1,2,3] the output should be 6\nFor lst = [] the output should be 0\nFor lst = [-1,-5,2,-1,-5] the output should be -126"} +{"task_id": "JavaScript/143", "prompt": "/*\n You are given a string representing a sentence,\n the sentence contains some words separated by a space,\n and you have to return a string that contains the words from the original sentence,\n whose lengths are prime numbers,\n the order of the words in the new string should be the same as the original one.\n\n Example 1:\n Input: sentence = \"This is a test\"\n Output: \"is\"\n\n Example 2:\n Input: sentence = \"lets go for swimming\"\n Output: \"go for\"\n\n Constraints:\n * 1 <= len(sentence) <= 100\n * sentence contains only letters\n */\nconst wordsInSentence = (sentence) => {\n", "canonical_solution": " let t = sentence.split(/\\s/)\n let p = ''\n for (let j = 0; j < t.length; j++) {\n let len = t[j].length;\n let u = 1\n if (len == 1 || len == 0) { continue }\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { u = 0 }\n }\n if (u == 0) { continue }\n if (p == '') { p += t[j] }\n else { p = p + ' ' + t[j] }\n }\n return p\n}\n\n", "test": "const testWordsInSentence = () => {\n console.assert(wordsInSentence('This is a test') === 'is')\n console.assert(wordsInSentence('lets go for swimming') === 'go for')\n console.assert(\n wordsInSentence('there is no place available here') === 'there is no place'\n )\n console.assert(wordsInSentence('Hi I am Hussein') === 'Hi am Hussein')\n console.assert(wordsInSentence('go for it') === 'go for it')\n console.assert(wordsInSentence('here') === '')\n console.assert(wordsInSentence('here is') === 'is')\n}\n\ntestWordsInSentence()\n", "declaration": "\nconst wordsInSentence = (sentence) => {\n", "example_test": "const testWordsInSentence = () => {\n console.assert(wordsInSentence('This is a test') === 'is')\n console.assert(wordsInSentence('lets go for swimming') === 'go for')\n}\ntestWordsInSentence()\n", "buggy_solution": " let t = sentence.split(/\\s/)\n let p = ''\n for (let j = 0; j < t.length; j++) {\n let len = t[j].length;\n let u = 1\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { u = 0 }\n }\n if (u == 0) { continue }\n if (p == '') { p += t[j] }\n else { p = p + ' ' + t[j] }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "wordsInSentence", "signature": "const wordsInSentence = (sentence)", "docstring": "You are given a string representing a sentence,\nthe sentence contains some words separated by a space,\nand you have to return a string that contains the words from the original sentence,\nwhose lengths are prime numbers,\nthe order of the words in the new string should be the same as the original one.\nExample 1:\nInput: sentence = \"This is a test\"\nOutput: \"is\"\nExample 2:\nInput: sentence = \"lets go for swimming\"\nOutput: \"go for\"\nConstraints:\n* 1 <= len(sentence) <= 100\n* sentence contains only letters", "instruction": "Write a JavaScript function `const wordsInSentence = (sentence)` to solve the following problem:\nYou are given a string representing a sentence,\nthe sentence contains some words separated by a space,\nand you have to return a string that contains the words from the original sentence,\nwhose lengths are prime numbers,\nthe order of the words in the new string should be the same as the original one.\nExample 1:\nInput: sentence = \"This is a test\"\nOutput: \"is\"\nExample 2:\nInput: sentence = \"lets go for swimming\"\nOutput: \"go for\"\nConstraints:\n* 1 <= len(sentence) <= 100\n* sentence contains only letters"} +{"task_id": "JavaScript/144", "prompt": "/*Your task is to implement a function that will simplify the expression\n x * n. The function returns true if x * n evaluates to a whole number and false\n otherwise. Both x and n, are string representation of a fraction, and have the following format,\n / where both numerator and denominator are positive whole numbers.\n\n You can assume that x, and n are valid fractions, and do not have zero as denominator.\n\n simplify(\"1/5\", \"5/1\") = true\n simplify(\"1/6\", \"2/1\") = false\n simplify(\"7/10\", \"10/2\") = false\n */\nconst simplify = (x, n) => {\n", "canonical_solution": " let a = x.split(/\\//)\n let b = n.split(/\\//)\n let m = Number(a[0]) * Number(b[0])\n let r = Number(a[1]) * Number(b[1])\n return m % r == 0\n}\n\n", "test": "const testSimplify = () => {\n console.assert(simplify('1/5', '5/1') === true)\n console.assert(simplify('1/6', '2/1') === false)\n console.assert(simplify('5/1', '3/1') === true)\n console.assert(simplify('7/10', '10/2') === false)\n console.assert(simplify('2/10', '50/10') === true)\n console.assert(simplify('7/2', '4/2') === true)\n console.assert(simplify('11/6', '6/1') === true)\n console.assert(simplify('2/3', '5/2') === false)\n console.assert(simplify('5/2', '3/5') === false)\n console.assert(simplify('2/4', '8/4') === true)\n console.assert(simplify('2/4', '4/2') === true)\n console.assert(simplify('1/5', '5/1') === true)\n console.assert(simplify('1/5', '1/5') === false)\n}\n\ntestSimplify()\n", "declaration": "\nconst simplify = (x, n) => {\n", "example_test": "const testSimplify = () => {\n console.assert(simplify('1/5', '5/1') === true)\n console.assert(simplify('1/6', '2/1') === false)\n console.assert(simplify('7/10', '10/2') === false)\n}\ntestSimplify()\n", "buggy_solution": " let a = x.split(/\\//)\n let b = n.split(/\\//)\n let m = r * Number(a[0]) * Number(b[0])\n let r = m * Number(a[1]) * Number(b[1])\n let m = r * Number(a[1])\n let r = m * Number(b[1])\n return m % r == 0\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "simplify", "signature": "const simplify = (x, n)", "docstring": "Your task is to implement a function that will simplify the expression\nx * n. The function returns true if x * n evaluates to a whole number and false\notherwise. Both x and n, are string representation of a fraction, and have the following format,\n/ where both numerator and denominator are positive whole numbers.\nYou can assume that x, and n are valid fractions, and do not have zero as denominator.\nsimplify(\"1/5\", \"5/1\") = true\nsimplify(\"1/6\", \"2/1\") = false\nsimplify(\"7/10\", \"10/2\") = false", "instruction": "Write a JavaScript function `const simplify = (x, n)` to solve the following problem:\nYour task is to implement a function that will simplify the expression\nx * n. The function returns true if x * n evaluates to a whole number and false\notherwise. Both x and n, are string representation of a fraction, and have the following format,\n/ where both numerator and denominator are positive whole numbers.\nYou can assume that x, and n are valid fractions, and do not have zero as denominator.\nsimplify(\"1/5\", \"5/1\") = true\nsimplify(\"1/6\", \"2/1\") = false\nsimplify(\"7/10\", \"10/2\") = false"} +{"task_id": "JavaScript/145", "prompt": "/*\n Write a function which sorts the given list of integers\n in ascending order according to the sum of their digits.\n Note: if there are several items with similar sum of their digits,\n order them based on their index in original list.\n\n For example:\n >>> orderByPoints([1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]\n >>> orderByPoints([]) == []\n */\nconst orderByPoints = (nums) => {\n", "canonical_solution": " let p = nums\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let m = 0\n let n = 0\n let h = p[k]\n let d = p[k + 1]\n let y = 1\n let u = 1\n if (h < 0) { y = -1; h = -h; }\n if (d < 0) { u = -1; d = -d; }\n while (h >= 10) {\n m += h % 10;\n h = (h - h % 10) / 10;\n }\n m += y * h\n while (d >= 10) {\n n += d % 10;\n d = (d - d % 10) / 10;\n }\n n += u * d\n if (m > n) {\n let tmp = p[k]\n p[k] = p[k + 1]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "test": "const testOrderByPoints = () => {\n console.assert(\n JSON.stringify(orderByPoints([1, 11, -1, -11, -12])) ===\n JSON.stringify([-1, -11, 1, -12, 11])\n )\n console.assert(\n JSON.stringify(\n orderByPoints([\n 1234, 423, 463, 145, 2, 423, 423, 53, 6, 37, 3457, 3, 56, 0, 46,\n ])\n ) ===\n JSON.stringify([\n 0, 2, 3, 6, 53, 423, 423, 423, 1234, 145, 37, 46, 56, 463, 3457,\n ])\n )\n console.assert(JSON.stringify(orderByPoints([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(orderByPoints([1, -11, -32, 43, 54, -98, 2, -3])) ===\n JSON.stringify([-3, -32, -98, -11, 1, 2, 43, 54])\n )\n console.assert(\n JSON.stringify(orderByPoints([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])) ===\n JSON.stringify([1, 10, 2, 11, 3, 4, 5, 6, 7, 8, 9])\n )\n console.assert(\n JSON.stringify(orderByPoints([0, 6, 6, -76, -21, 23, 4])) ===\n JSON.stringify([-76, -21, 0, 4, 23, 6, 6])\n )\n}\n\ntestOrderByPoints()\n", "declaration": "\nconst orderByPoints = (nums) => {\n", "example_test": "const testOrderByPoints = () => {\n console.assert(\n JSON.stringify(orderByPoints([1, 11, -1, -11, -12])) ===\n JSON.stringify([-1, -11, 1, -12, 11])\n )\n console.assert(JSON.stringify(orderByPoints([])) === JSON.stringify([]))\n}\ntestOrderByPoints()\n", "buggy_solution": " let p = nums\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let m = 0\n let n = 0\n let h = p[k]\n let d = p[k + 1]\n let y = 1\n let u = 1\n if (h < 0) { y = -1; h = -h; }\n if (d < 0) { u = -1; d = -d; }\n while (h >= 10) {\n m += h % 10;\n h = (h - h % 10) / 10;\n }\n m += y * h + h\n while (d >= 10) {\n n += d % 10;\n d = (d - d % 10) / 10;\n }\n n += u * d\n if (m > n) {\n let tmp = p[k]\n p[k] = p[k + 1]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "orderByPoints", "signature": "const orderByPoints = (nums)", "docstring": "Write a function which sorts the given list of integers\nin ascending order according to the sum of their digits.\nNote: if there are several items with similar sum of their digits,\norder them based on their index in original list.\nFor example:\n>>> orderByPoints([1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]\n>>> orderByPoints([]) == []", "instruction": "Write a JavaScript function `const orderByPoints = (nums)` to solve the following problem:\nWrite a function which sorts the given list of integers\nin ascending order according to the sum of their digits.\nNote: if there are several items with similar sum of their digits,\norder them based on their index in original list.\nFor example:\n>>> orderByPoints([1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]\n>>> orderByPoints([]) == []"} +{"task_id": "JavaScript/146", "prompt": "/*Write a function that takes an array of numbers as input and returns \n the number of elements in the array that are greater than 10 and both \n first and last digits of a number are odd (1, 3, 5, 7, 9).\n For example:\n specialFilter([15, -73, 14, -15]) => 1 \n specialFilter([33, -2, -3, 45, 21, 109]) => 2\n */\nconst specialFilter = (nums) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < nums.length; i++) {\n if (nums[i] < 10) { continue }\n let y = nums[i].toString()\n if (Number(y[0]) % 2 == 1 && Number(y[y.length - 1]) % 2 == 1) {\n p++\n }\n }\n return p\n}\n\n", "test": "const testSpecialFilter = () => {\n console.assert(specialFilter([5, -2, 1, -5]) === 0)\n console.assert(specialFilter([15, -73, 14, -15]) === 1)\n console.assert(specialFilter([33, -2, -3, 45, 21, 109]) === 2)\n console.assert(specialFilter([43, -12, 93, 125, 121, 109]) === 4)\n console.assert(specialFilter([71, -2, -33, 75, 21, 19]) === 3)\n console.assert(specialFilter([1]) === 0)\n console.assert(specialFilter([]) === 0)\n}\n\ntestSpecialFilter()\n", "declaration": "\nconst specialFilter = (nums) => {\n", "example_test": "const testSpecialFilter = () => {\n console.assert(specialFilter([15, -73, 14, -15]) === 1)\n console.assert(specialFilter([33, -2, -3, 45, 21, 109]) === 2)\n}\ntestSpecialFilter()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < nums.length; i++) {\n if (nums[i] < 10) { continue }\n let y = nums[i].toString()\n if (Number(y[0]) % 2 == 1 && Number(y[y.length - 1]) % 2 == 1 && Number(y[y.length - 1]) % 2 == 0) {\n p++\n }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "specialFilter", "signature": "const specialFilter = (nums)", "docstring": "Write a function that takes an array of numbers as input and returns\nthe number of elements in the array that are greater than 10 and both\nfirst and last digits of a number are odd (1, 3, 5, 7, 9).\nFor example:\nspecialFilter([15, -73, 14, -15]) => 1\nspecialFilter([33, -2, -3, 45, 21, 109]) => 2", "instruction": "Write a JavaScript function `const specialFilter = (nums)` to solve the following problem:\nWrite a function that takes an array of numbers as input and returns\nthe number of elements in the array that are greater than 10 and both\nfirst and last digits of a number are odd (1, 3, 5, 7, 9).\nFor example:\nspecialFilter([15, -73, 14, -15]) => 1\nspecialFilter([33, -2, -3, 45, 21, 109]) => 2"} +{"task_id": "JavaScript/147", "prompt": "/*\n You are given a positive integer n. You have to create an integer array a of length n.\n For each i (1 \u2264 i \u2264 n), the value of a[i] = i * i - i + 1.\n Return the number of triples (a[i], a[j], a[k]) of a where i < j < k, \n and a[i] + a[j] + a[k] is a multiple of 3.\n\n Example :\n Input: n = 5\n Output: 1\n Explanation: \n a = [1, 3, 7, 13, 21]\n The only valid triple is (1, 7, 13).\n */\nconst getMaxTriples = (n) => {\n", "canonical_solution": " let y = []\n for (let i = 1; i <= n; i++) {\n y.push(i * i - i + 1)\n }\n let u = 0\n for (let i = 0; i < n - 2; i++) {\n for (let j = i + 1; j < n - 1; j++) {\n for (let k = j + 1; k < n; k++) {\n if ((y[i] + y[j] + y[k]) % 3 == 0) { u++ }\n }\n }\n }\n return u\n}\n\n", "test": "const testGetMaxTriples = () => {\n console.assert(getMaxTriples(5) === 1)\n console.assert(getMaxTriples(6) === 4)\n console.assert(getMaxTriples(10) === 36)\n console.assert(getMaxTriples(100) === 53361)\n}\n\ntestGetMaxTriples()\n", "declaration": "\nconst getMaxTriples = (n) => {\n", "example_test": "const testGetMaxTriples = () => {\n console.assert(getMaxTriples(5) === 1)\n}\ntestGetMaxTriples()\n", "buggy_solution": " let y = []\n for (let i = 1; i <= n; i++) {\n y.push(i)\n }\n let u = 0\n for (let i = 0; i < n - 2; i++) {\n for (let j = i + 1; j < n - 1; j++) {\n for (let k = j + 1; k < n; k++) {\n if ((y[i] + y[j] + y[k]) % 3 == 0) { u++ }\n }\n }\n }\n return u\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "getMaxTriples", "signature": "const getMaxTriples = (n)", "docstring": "You are given a positive integer n. You have to create an integer array a of length n.\nFor each i (1 \u2264 i \u2264 n), the value of a[i] = i * i - i + 1.\nReturn the number of triples (a[i], a[j], a[k]) of a where i < j < k,\nand a[i] + a[j] + a[k] is a multiple of 3.\nExample :\nInput: n = 5\nOutput: 1\nExplanation:\na = [1, 3, 7, 13, 21]\nThe only valid triple is (1, 7, 13).", "instruction": "Write a JavaScript function `const getMaxTriples = (n)` to solve the following problem:\nYou are given a positive integer n. You have to create an integer array a of length n.\nFor each i (1 \u2264 i \u2264 n), the value of a[i] = i * i - i + 1.\nReturn the number of triples (a[i], a[j], a[k]) of a where i < j < k,\nand a[i] + a[j] + a[k] is a multiple of 3.\nExample :\nInput: n = 5\nOutput: 1\nExplanation:\na = [1, 3, 7, 13, 21]\nThe only valid triple is (1, 7, 13)."} +{"task_id": "JavaScript/148", "prompt": "/* There are eight planets in our solar system: the closerst to the Sun\n is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,\n Uranus, Neptune.\n Write a function that takes two planet names as strings planet1 and planet2.\n The function should return a tuple containing all planets whose orbits are\n located between the orbit of planet1 and the orbit of planet2, sorted by\n the proximity to the sun.\n The function should return an empty tuple if planet1 or planet2\n are not correct planet names.\n Examples\n bf(\"Jupiter\", \"Neptune\") ==> (\"Saturn\", \"Uranus\")\n bf(\"Earth\", \"Mercury\") ==> (\"Venus\")\n bf(\"Mercury\", \"Uranus\") ==> (\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\")\n */\nconst bf = (planet1, planet2) => {\n", "canonical_solution": " let y = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']\n let u = []\n let lo = -1\n let hi = -1\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet1) { lo = i }\n }\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet2) { hi = i }\n }\n if (lo == -1 || hi == -1 || lo == hi) { return [] }\n if (lo > hi) {\n let tmp = lo;\n lo = hi;\n hi = tmp;\n }\n for (let i = lo + 1; i < hi; i++) {\n u.push(y[i])\n }\n return u\n}\n\n", "test": "const testBf = () => {\n console.assert(\n JSON.stringify(bf('Jupiter', 'Neptune')) ===\n JSON.stringify(['Saturn', 'Uranus'])\n )\n console.assert(\n JSON.stringify(bf('Earth', 'Mercury')) === JSON.stringify(['Venus'])\n )\n console.assert(\n JSON.stringify(bf('Mercury', 'Uranus')) ===\n JSON.stringify(['Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn'])\n )\n console.assert(\n JSON.stringify(bf('Neptune', 'Venus')) ===\n JSON.stringify(['Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus'])\n )\n console.assert(JSON.stringify(bf('Earth', 'Earth')) === JSON.stringify([]))\n console.assert(JSON.stringify(bf('Mars', 'Earth')) === JSON.stringify([]))\n console.assert(\n JSON.stringify(bf('Jupiter', 'Makemake')) === JSON.stringify([])\n )\n}\n\ntestBf()\n", "declaration": "\nconst bf = (planet1, planet2) => {\n", "example_test": "const testBf = () => {\n console.assert(\n JSON.stringify(bf('Jupiter', 'Neptune')) ===\n JSON.stringify(['Saturn', 'Uranus'])\n )\n console.assert(\n JSON.stringify(bf('Earth', 'Mercury')) === JSON.stringify(['Venus'])\n )\n console.assert(\n JSON.stringify(bf('Mercury', 'Uranus')) ===\n JSON.stringify(['Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn'])\n )\n}\ntestBf()\n", "buggy_solution": " let y = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupyter', 'Saturn', 'Uranus', 'Neptune']\n let u = []\n let lo = -1\n let hi = -1\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet1) { lo = i }\n }\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet2) { hi = i }\n }\n if (lo == -1 || hi == -1 || lo == hi) { return [] }\n if (lo > hi) {\n let tmp = lo;\n lo = hi;\n hi = tmp;\n }\n for (let i = lo + 1; i < hi; i++) {\n u.push(y[i])\n }\n return u\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "bf", "signature": "const bf = (planet1, planet2)", "docstring": "There are eight planets in our solar system: the closerst to the Sun\nis Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,\nUranus, Neptune.\nWrite a function that takes two planet names as strings planet1 and planet2.\nThe function should return a tuple containing all planets whose orbits are\nlocated between the orbit of planet1 and the orbit of planet2, sorted by\nthe proximity to the sun.\nThe function should return an empty tuple if planet1 or planet2\nare not correct planet names.\nExamples\nbf(\"Jupiter\", \"Neptune\") ==> (\"Saturn\", \"Uranus\")\nbf(\"Earth\", \"Mercury\") ==> (\"Venus\")\nbf(\"Mercury\", \"Uranus\") ==> (\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\")", "instruction": "Write a JavaScript function `const bf = (planet1, planet2)` to solve the following problem:\nThere are eight planets in our solar system: the closerst to the Sun\nis Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,\nUranus, Neptune.\nWrite a function that takes two planet names as strings planet1 and planet2.\nThe function should return a tuple containing all planets whose orbits are\nlocated between the orbit of planet1 and the orbit of planet2, sorted by\nthe proximity to the sun.\nThe function should return an empty tuple if planet1 or planet2\nare not correct planet names.\nExamples\nbf(\"Jupiter\", \"Neptune\") ==> (\"Saturn\", \"Uranus\")\nbf(\"Earth\", \"Mercury\") ==> (\"Venus\")\nbf(\"Mercury\", \"Uranus\") ==> (\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\")"} +{"task_id": "JavaScript/149", "prompt": "/*Write a function that accepts a list of strings as a parameter,\n deletes the strings that have odd lengths from it,\n and returns the resulted list with a sorted order,\n The list is always a list of strings and never an array of numbers,\n and it may contain duplicates.\n The order of the list should be ascending by length of each word, and you\n should return the list sorted by that rule.\n If two words have the same length, sort the list alphabetically.\n The function should return a list of strings in sorted order.\n You may assume that all words will have the same length.\n For example:\n assert list_sort([\"aa\", \"a\", \"aaa\"]) => [\"aa\"]\n assert list_sort([\"ab\", \"a\", \"aaa\", \"cd\"]) => [\"ab\", \"cd\"]\n */\nconst sortedListSum = (lst) => {\n", "canonical_solution": " let p = []\n for (let i = 0; i < lst.length; i++) {\n if (lst[i].length % 2 == 0) {\n p.push(lst[i])\n }\n }\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let f = 0\n if (p[k].length > p[k + 1].length) { f = 1 }\n if (p[k].length == p[k + 1].length) {\n let r = p[k].length\n for (let l = 0; l < r; l++) {\n if (p[k][l].charCodeAt() > p[k + 1][l].charCodeAt()) {\n f = 1;\n break;\n }\n if (p[k][l].charCodeAt() < p[k + 1][l].charCodeAt()) {\n break;\n }\n }\n }\n if (f == 1) {\n let tmp = p[k]\n p[k] = p[k + 1]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "test": "const testSortedListSum = () => {\n console.assert(\n JSON.stringify(sortedListSum(['aa', 'a', 'aaa'])) === JSON.stringify(['aa'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['school', 'AI', 'asdf', 'b'])) ===\n JSON.stringify(['AI', 'asdf', 'school'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['d', 'b', 'c', 'a'])) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(sortedListSum(['d', 'dcba', 'abcd', 'a'])) ===\n JSON.stringify(['abcd', 'dcba'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['AI', 'ai', 'au'])) ===\n JSON.stringify(['AI', 'ai', 'au'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['a', 'b', 'b', 'c', 'c', 'a'])) ===\n JSON.stringify([])\n )\n console.assert(\n JSON.stringify(sortedListSum(['aaaa', 'bbbb', 'dd', 'cc'])) ===\n JSON.stringify(['cc', 'dd', 'aaaa', 'bbbb'])\n )\n}\n\ntestSortedListSum()\n", "declaration": "\nconst sortedListSum = (lst) => {\n", "example_test": "const testSortedListSum = () => {\n console.assert(\n JSON.stringify(sortedListSum(['aa', 'a', 'aaa'])) === JSON.stringify(['aa'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['ab', 'a', 'aaa', 'cd'])) ===\n JSON.stringify(['ab', 'cd'])\n )\n}\ntestSortedListSum()\n", "buggy_solution": " let p = []\n for (let i = 0; i < lst.length; i++) {\n if (lst[i].length % 2 == 0) {\n p.push(lst[i])\n }\n }\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let f = 0\n if (p[k].length > p[k + 1].length) { f = 1 }\n if (p[k].length == p[k + 1].length) {\n let r = p[k].length\n for (let l = 0; l < r; l++) {\n if (p[k][l].charCodeAt() > p[k + 1][l].charCodeAt()) {\n f = 1;\n break;\n }\n if (p[k][l].charCodeAt() < p[k + 1][l].charCodeAt()) {\n break;\n }\n }\n }\n if (f == 1) {\n let tmp = p[k]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sortedListSum", "signature": "const sortedListSum = (lst)", "docstring": "Write a function that accepts a list of strings as a parameter,\ndeletes the strings that have odd lengths from it,\nand returns the resulted list with a sorted order,\nThe list is always a list of strings and never an array of numbers,\nand it may contain duplicates.\nThe order of the list should be ascending by length of each word, and you\nshould return the list sorted by that rule.\nIf two words have the same length, sort the list alphabetically.\nThe function should return a list of strings in sorted order.\nYou may assume that all words will have the same length.\nFor example:\nassert list_sort([\"aa\", \"a\", \"aaa\"]) => [\"aa\"]\nassert list_sort([\"ab\", \"a\", \"aaa\", \"cd\"]) => [\"ab\", \"cd\"]", "instruction": "Write a JavaScript function `const sortedListSum = (lst)` to solve the following problem:\nWrite a function that accepts a list of strings as a parameter,\ndeletes the strings that have odd lengths from it,\nand returns the resulted list with a sorted order,\nThe list is always a list of strings and never an array of numbers,\nand it may contain duplicates.\nThe order of the list should be ascending by length of each word, and you\nshould return the list sorted by that rule.\nIf two words have the same length, sort the list alphabetically.\nThe function should return a list of strings in sorted order.\nYou may assume that all words will have the same length.\nFor example:\nassert list_sort([\"aa\", \"a\", \"aaa\"]) => [\"aa\"]\nassert list_sort([\"ab\", \"a\", \"aaa\", \"cd\"]) => [\"ab\", \"cd\"]"} +{"task_id": "JavaScript/150", "prompt": "/*A simple program which should return the value of x if n is \n a prime number and should return the value of y otherwise.\n\n Examples:\n for xOrY(7, 34, 12) == 34\n for xOrY(15, 8, 5) == 5\n \n */\nconst xOrY = (n, x, y) => {\n", "canonical_solution": " let len = n\n if (len == 1 || len == 0) { return y }\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { return y }\n }\n return x\n}\n\n", "test": "const testXOrY = () => {\n console.assert(xOrY(7, 34, 12) === 34)\n console.assert(xOrY(15, 8, 5) === 5)\n console.assert(xOrY(3, 33, 5212) === 33)\n console.assert(xOrY(1259, 3, 52) === 3)\n console.assert(xOrY(7919, -1, 12) === -1)\n console.assert(xOrY(3609, 1245, 583) === 583)\n console.assert(xOrY(91, 56, 129) === 129)\n console.assert(xOrY(6, 34, 1234) === 1234)\n console.assert(xOrY(1, 2, 0) === 0)\n console.assert(xOrY(2, 2, 0) === 2)\n}\n\ntestXOrY()\n", "declaration": "\nconst xOrY = (n, x, y) => {\n", "example_test": "const testXOrY = () => {\n console.assert(xOrY(7, 34, 12) === 34)\n console.assert(xOrY(15, 8, 5) === 5)\n}\ntestXOrY()\n", "buggy_solution": " let len = n\n if (len == 1 || len == 0) { return y }\n for (let i = 2; i * i <= len; i++) {\n if (len % i - 1 == 0) { return y }\n }\n return x\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "xOrY", "signature": "const xOrY = (n, x, y)", "docstring": "A simple program which should return the value of x if n is\na prime number and should return the value of y otherwise.\nExamples:\nfor xOrY(7, 34, 12) == 34\nfor xOrY(15, 8, 5) == 5", "instruction": "Write a JavaScript function `const xOrY = (n, x, y)` to solve the following problem:\nA simple program which should return the value of x if n is\na prime number and should return the value of y otherwise.\nExamples:\nfor xOrY(7, 34, 12) == 34\nfor xOrY(15, 8, 5) == 5"} +{"task_id": "JavaScript/151", "prompt": "/* Given a list of numbers, return the sum of squares of the numbers\n in the list that are odd. Ignore numbers that are negative or not integers.\n doubleTheDifference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10\n doubleTheDifference([-1, -2, 0]) == 0\n doubleTheDifference([9, -2]) == 81\n doubleTheDifference([0]) == 0\n If the input list is empty, return 0.\n */\nconst doubleTheDifference = (lst) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] % 2 == 1 && lst[i] > 0) {\n p += lst[i] * lst[i]\n }\n }\n return p\n}\n\n", "test": "const testDoubleTheDifference = () => {\n console.assert(doubleTheDifference([]) === 0)\n console.assert(doubleTheDifference([5, 4]) === 25)\n console.assert(doubleTheDifference([0.1, 0.2, 0.3]) === 0)\n console.assert(doubleTheDifference([-10, -20, -30]) === 0)\n console.assert(doubleTheDifference([-1, -2, 8]) === 0)\n console.assert(doubleTheDifference([0.2, 3, 5]) === 34)\n let lst = []\n let odd_sum = 0\n for (let i = -99; i < 100; i += 2) {\n if (i % 2 != 0 && i > 0) { odd_sum += i * i }\n lst.push(i)\n }\n console.assert(doubleTheDifference(lst) === odd_sum)\n}\ntestDoubleTheDifference()\n", "declaration": "\nconst doubleTheDifference = (lst) => {\n", "example_test": "const testDoubleTheDifference = () => {\n console.assert(doubleTheDifference([1,3,2,0]) === 10)\n console.assert(doubleTheDifference([-1,-2,0]) === 0)\n console.assert(doubleTheDifference([9,-2]) === 81)\n console.assert(doubleTheDifference([0]) === 0)\n}\ntestDoubleTheDifference()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] > 0) {\n p += lst[i]\n }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "doubleTheDifference", "signature": "const doubleTheDifference = (lst)", "docstring": "Given a list of numbers, return the sum of squares of the numbers\nin the list that are odd. Ignore numbers that are negative or not integers.\ndoubleTheDifference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10\ndoubleTheDifference([-1, -2, 0]) == 0\ndoubleTheDifference([9, -2]) == 81\ndoubleTheDifference([0]) == 0\nIf the input list is empty, return 0.", "instruction": "Write a JavaScript function `const doubleTheDifference = (lst)` to solve the following problem:\nGiven a list of numbers, return the sum of squares of the numbers\nin the list that are odd. Ignore numbers that are negative or not integers.\ndoubleTheDifference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10\ndoubleTheDifference([-1, -2, 0]) == 0\ndoubleTheDifference([9, -2]) == 81\ndoubleTheDifference([0]) == 0\nIf the input list is empty, return 0."} +{"task_id": "JavaScript/152", "prompt": "/*I think we all remember that feeling when the result of some long-awaited\n event is finally known. The feelings and thoughts you have at that moment are\n definitely worth noting down and comparing.\n Your task is to determine if a person correctly guessed the results of a number of matches.\n You are given two arrays of scores and guesses of equal length, where each index shows a match. \n Return an array of the same length denoting how far off each guess was. If they have guessed correctly,\n the value is 0, and if not, the value is the absolute difference between the guess and the score.\n \n \n example:\n\n compare([1,2,3,4,5,1],[1,2,3,4,2,-2]) -> [0,0,0,0,3,3]\n compare([0,5,0,0,0,4],[4,1,1,0,0,-2]) -> [4,4,1,0,0,6]\n */\nconst compare = (game, guess) => {\n", "canonical_solution": " for (let i = 0; i < guess.length; i++) {\n game[i] -= guess[i]\n if (game[i]<0)\n game[i]=-game[i]; }\n return game\n}\n\n", "test": "const testCompare = () => {\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0,5,0,0,0,4],[4,1,1,0,0,-2])) ===\n JSON.stringify([4,4,1,0,0,6])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0])) ===\n JSON.stringify([0, 0, 0, 0, 0, 0])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3], [-1, -2, -3])) ===\n JSON.stringify([2, 4, 6])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3, 5], [-1, 2, 3, 4])) ===\n JSON.stringify([2, 0, 0, 1])\n )\n}\n\ntestCompare()\n", "declaration": "\nconst compare = (game, guess) => {\n", "example_test": "const testCompare = () => {\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0,5,0,0,0,4],[4,1,1,0,0,-2])) ===\n JSON.stringify([4,4,1,0,0,6])\n )\n}\ntestCompare()\n", "buggy_solution": " for (let i = 0; i < guess.length; i++) {\n game[i] -= guess[i]\n if (game[i]<0)\n game[i]=-game[i];\n if (guess[i]!=0)\n game[i]-=guess[i]; }\n return game\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "compare", "signature": "const compare = (game, guess)", "docstring": "I think we all remember that feeling when the result of some long-awaited\nevent is finally known. The feelings and thoughts you have at that moment are\ndefinitely worth noting down and comparing.\nYour task is to determine if a person correctly guessed the results of a number of matches.\nYou are given two arrays of scores and guesses of equal length, where each index shows a match.\nReturn an array of the same length denoting how far off each guess was. If they have guessed correctly,\nthe value is 0, and if not, the value is the absolute difference between the guess and the score.\nexample:\ncompare([1,2,3,4,5,1],[1,2,3,4,2,-2]) -> [0,0,0,0,3,3]\ncompare([0,5,0,0,0,4],[4,1,1,0,0,-2]) -> [4,4,1,0,0,6]", "instruction": "Write a JavaScript function `const compare = (game, guess)` to solve the following problem:\nI think we all remember that feeling when the result of some long-awaited\nevent is finally known. The feelings and thoughts you have at that moment are\ndefinitely worth noting down and comparing.\nYour task is to determine if a person correctly guessed the results of a number of matches.\nYou are given two arrays of scores and guesses of equal length, where each index shows a match.\nReturn an array of the same length denoting how far off each guess was. If they have guessed correctly,\nthe value is 0, and if not, the value is the absolute difference between the guess and the score.\nexample:\ncompare([1,2,3,4,5,1],[1,2,3,4,2,-2]) -> [0,0,0,0,3,3]\ncompare([0,5,0,0,0,4],[4,1,1,0,0,-2]) -> [4,4,1,0,0,6]"} +{"task_id": "JavaScript/153", "prompt": "/*You will be given the name of a class (a string) and a list of extensions.\n The extensions are to be used to load additional classes to the class. The\n strength of the extension is as follows: Let CAP be the number of the uppercase\n letters in the extension's name, and let SM be the number of lowercase letters\n in the extension's name, the strength is given by the fraction CAP - SM.\n You should find the strongest extension and return a string in this\n format: ClassName.StrongestExtensionName.\n If there are two or more extensions with the same strength, you should\n choose the one that comes first in the list.\n For example, if you are given \"Slices\" as the class and a list of the\n extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should\n return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension\n (its strength is -1).\n Example:\n for strongestExtension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA'\n */\nconst strongestExtension = (class_name, extensions) => {\n", "canonical_solution": " let u = 0\n let s = -Infinity\n for (let i = extensions.length - 1; i >= 0; i--) {\n let y = 0\n for (let j = 0; j < extensions[i].length; j++) {\n let k = extensions[i][j].charCodeAt()\n if (k >= 65 && k <= 90) { y += 1 }\n if (k >= 97 && k <= 122) { y -= 1 }\n }\n if (y >= s) {\n s = y;\n u = i;\n }\n }\n return class_name + '.' + extensions[u]\n}\n\n", "test": "const testStrongestExtension = () => {\n console.assert(\n strongestExtension('Watashi', ['tEN', 'niNE', 'eIGHt8OKe']) ===\n 'Watashi.eIGHt8OKe'\n )\n console.assert(\n strongestExtension('Boku123', [\n 'nani',\n 'NazeDa',\n 'YEs.WeCaNe',\n '32145tggg',\n ]) === 'Boku123.YEs.WeCaNe'\n )\n console.assert(\n strongestExtension('__YESIMHERE', [\n 't',\n 'eMptY',\n 'nothing',\n 'zeR00',\n 'NuLl__',\n '123NoooneB321',\n ]) === '__YESIMHERE.NuLl__'\n )\n console.assert(\n strongestExtension('K', ['Ta', 'TAR', 't234An', 'cosSo']) === 'K.TAR'\n )\n console.assert(\n strongestExtension('__HAHA', ['Tab', '123', '781345', '-_-']) ===\n '__HAHA.123'\n )\n console.assert(\n strongestExtension('YameRore', [\n 'HhAas',\n 'okIWILL123',\n 'WorkOut',\n 'Fails',\n '-_-',\n ]) === 'YameRore.okIWILL123'\n )\n console.assert(\n strongestExtension('finNNalLLly', ['Die', 'NowW', 'Wow', 'WoW']) ===\n 'finNNalLLly.WoW'\n )\n console.assert(strongestExtension('_', ['Bb', '91245']) === '_.Bb')\n console.assert(strongestExtension('Sp', ['671235', 'Bb']) === 'Sp.671235')\n}\n\ntestStrongestExtension()\n", "declaration": "\nconst strongestExtension = (class_name, extensions) => {\n", "example_test": "const testStrongestExtension = () => {\n console.assert(\n strongestExtension('my_class', ['AA', 'Be', 'CC']) ===\n 'my_class.AA'\n )\n}\ntestStrongestExtension()\n", "buggy_solution": " let u = 0\n let s = -Infinity\n for (let i = extensions.length - 1; i >= 0; i--) {\n let y = 0\n for (let j = 0; j < extensions[i].length; j++) {\n let k = extensions[i][j].charCodeAt()\n if (k >= 65 && k <= 90) { y += 1 }\n if (k >= 97 && k <= 122) { y -= 1 }\n }\n if (y >= s) {\n s = y;\n u = i;\n }\n }\n return class_name + extensions[u]\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "strongestExtension", "signature": "const strongestExtension = (class_name, extensions)", "docstring": "You will be given the name of a class (a string) and a list of extensions.\nThe extensions are to be used to load additional classes to the class. The\nstrength of the extension is as follows: Let CAP be the number of the uppercase\nletters in the extension's name, and let SM be the number of lowercase letters\nin the extension's name, the strength is given by the fraction CAP - SM.\nYou should find the strongest extension and return a string in this\nformat: ClassName.StrongestExtensionName.\nIf there are two or more extensions with the same strength, you should\nchoose the one that comes first in the list.\nFor example, if you are given \"Slices\" as the class and a list of the\nextensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should\nreturn 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension\n(its strength is -1).\nExample:\nfor strongestExtension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA'", "instruction": "Write a JavaScript function `const strongestExtension = (class_name, extensions)` to solve the following problem:\nYou will be given the name of a class (a string) and a list of extensions.\nThe extensions are to be used to load additional classes to the class. The\nstrength of the extension is as follows: Let CAP be the number of the uppercase\nletters in the extension's name, and let SM be the number of lowercase letters\nin the extension's name, the strength is given by the fraction CAP - SM.\nYou should find the strongest extension and return a string in this\nformat: ClassName.StrongestExtensionName.\nIf there are two or more extensions with the same strength, you should\nchoose the one that comes first in the list.\nFor example, if you are given \"Slices\" as the class and a list of the\nextensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should\nreturn 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension\n(its strength is -1).\nExample:\nfor strongestExtension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA'"} +{"task_id": "JavaScript/154", "prompt": "/*You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word\n cycpatternCheck(\"abcd\",\"abd\") => false\n cycpatternCheck(\"hello\",\"ell\") => true\n cycpatternCheck(\"whassup\",\"psus\") => false\n cycpatternCheck(\"abab\",\"baa\") => true\n cycpatternCheck(\"efef\",\"eeff\") => false\n cycpatternCheck(\"himenss\",\"simen\") => true\n */\nconst cycpatternCheck = (a, b) => {\n", "canonical_solution": " let l = b.length\n let pat = b + b\n for (let i = 0; i < a.length - l + 1; i++) {\n for (let j = 0; j < l + 1; j++) {\n let y = 1\n for (let k = 0; k < l; k++) {\n if (a[i + k] != pat[j + k]) { y = 0 }\n }\n if (y == 1) {\n return true\n }\n }\n }\n return false\n}\n\n", "test": "const testCycpatternCheck = () => {\n console.assert(cycpatternCheck('xyzw', 'xyw') === false)\n console.assert(cycpatternCheck('yello', 'ell') === true)\n console.assert(cycpatternCheck('whattup', 'ptut') === false)\n console.assert(cycpatternCheck('efef', 'fee') === true)\n console.assert(cycpatternCheck('abab', 'aabb') === false)\n console.assert(cycpatternCheck('winemtt', 'tinem') === true)\n}\n\ntestCycpatternCheck()\n", "declaration": "\nconst cycpatternCheck = (a, b) => {\n", "example_test": "const testCycpatternCheck = () => {\n console.assert(cycpatternCheck('abcd', 'abd') === false)\n console.assert(cycpatternCheck('hello', 'ell') === true)\n console.assert(cycpatternCheck('whassup', 'psus') === false)\n console.assert(cycpatternCheck('abab', 'baa') === true)\n console.assert(cycpatternCheck('efef', 'eeff') === false)\n console.assert(cycpatternCheck('himenss', 'simen') === true)\n}\ntestCycpatternCheck()\n", "buggy_solution": " let l = b.length\n let pat = b + b\n for (let i = 0; i < a.length - l + 1; i++) {\n for (let j = 0; j < b.length - l + 1; j++) {\n let y = 1\n for (let k = 0; k < l; k++) {\n if (a[i + k] != pat[j + k]) { y = 0 }\n }\n if (y == 1) {\n return true\n }\n }\n }\n return false\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "cycpatternCheck", "signature": "const cycpatternCheck = (a, b)", "docstring": "You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word\ncycpatternCheck(\"abcd\",\"abd\") => false\ncycpatternCheck(\"hello\",\"ell\") => true\ncycpatternCheck(\"whassup\",\"psus\") => false\ncycpatternCheck(\"abab\",\"baa\") => true\ncycpatternCheck(\"efef\",\"eeff\") => false\ncycpatternCheck(\"himenss\",\"simen\") => true", "instruction": "Write a JavaScript function `const cycpatternCheck = (a, b)` to solve the following problem:\nYou are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word\ncycpatternCheck(\"abcd\",\"abd\") => false\ncycpatternCheck(\"hello\",\"ell\") => true\ncycpatternCheck(\"whassup\",\"psus\") => false\ncycpatternCheck(\"abab\",\"baa\") => true\ncycpatternCheck(\"efef\",\"eeff\") => false\ncycpatternCheck(\"himenss\",\"simen\") => true"} +{"task_id": "JavaScript/155", "prompt": "/*Given an integer. return a tuple that has the number of even and odd digits respectively.\n\n Example:\n evenOddCount(-12) ==> (1, 1)\n evenOddCount(123) ==> (1, 2)\n */\nconst evenOddCount = (num) => {\n", "canonical_solution": " let o = 0\n let e = 0\n if (num < 0) { num = -num }\n while (num > 0) {\n if (num % 2 == 0) { e++ }\n else { o++ }\n num = (num - num % 10) / 10\n }\n return (e, o)\n}\n\n", "test": "const testEvenOddCount = () => {\n console.assert(JSON.stringify(evenOddCount(7)) === JSON.stringify((0, 1)))\n console.assert(JSON.stringify(evenOddCount(-78)) === JSON.stringify((1, 1)))\n console.assert(JSON.stringify(evenOddCount(3452)) === JSON.stringify((2, 2)))\n console.assert(\n JSON.stringify(evenOddCount(346211)) === JSON.stringify((3, 3))\n )\n console.assert(\n JSON.stringify(evenOddCount(-345821)) === JSON.stringify((3, 3))\n )\n console.assert(JSON.stringify(evenOddCount(-2)) === JSON.stringify((1, 0)))\n console.assert(\n JSON.stringify(evenOddCount(-45347)) === JSON.stringify((2, 3))\n )\n console.assert(JSON.stringify(evenOddCount(0)) === JSON.stringify((1, 0)))\n}\n\ntestEvenOddCount()\n", "declaration": "\nconst evenOddCount = (num) => {\n", "example_test": "const testEvenOddCount = () => {\n console.assert(JSON.stringify(evenOddCount(-12)) === JSON.stringify((1, 1)))\n console.assert(JSON.stringify(evenOddCount(123)) === JSON.stringify((1, 2)))\n}\ntestEvenOddCount()\n", "buggy_solution": " let o = 0\n let e = 0\n if (num < 0) { num = -num }\n while (num > 0) {\n if (num % 2 == 0) { e++ }\n else { o++ }\n num = num - num % 10\n }\n return (e, o)\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "evenOddCount", "signature": "const evenOddCount = (num)", "docstring": "Given an integer. return a tuple that has the number of even and odd digits respectively.\nExample:\nevenOddCount(-12) ==> (1, 1)\nevenOddCount(123) ==> (1, 2)", "instruction": "Write a JavaScript function `const evenOddCount = (num)` to solve the following problem:\nGiven an integer. return a tuple that has the number of even and odd digits respectively.\nExample:\nevenOddCount(-12) ==> (1, 1)\nevenOddCount(123) ==> (1, 2)"} +{"task_id": "JavaScript/156", "prompt": "/*\n Given a positive integer, obtain its roman numeral equivalent as a string,\n and return it in lowercase.\n Restrictions: 1 <= num <= 1000\n\n Examples:\n >>> intToMiniRoman(19) == 'xix'\n >>> intToMiniRoman(152) == 'clii'\n >>> intToMiniRoman(426) == 'cdxxvi'\n */\nconst intToMiniRoman = (number) => {\n", "canonical_solution": " let num = [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000]\n let sym = ['i', 'iv', 'v', 'ix', 'x', 'xl', 'l', 'xc', 'c', 'cd', 'd', 'cm', 'm']\n let i = 12\n let res = ''\n while (number) {\n let div = (number - number % num[i]) / num[i]\n number = number % num[i]\n while (div) {\n res += sym[i]\n div -= 1\n }\n i -= 1\n }\n return res\n}\n\n", "test": "const testIntToMiniRoman = () => {\n console.assert(intToMiniRoman(19) === 'xix')\n console.assert(intToMiniRoman(152) === 'clii')\n console.assert(intToMiniRoman(251) === 'ccli')\n console.assert(intToMiniRoman(426) === 'cdxxvi')\n console.assert(intToMiniRoman(500) === 'd')\n console.assert(intToMiniRoman(1) === 'i')\n console.assert(intToMiniRoman(4) === 'iv')\n console.assert(intToMiniRoman(43) === 'xliii')\n console.assert(intToMiniRoman(90) === 'xc')\n console.assert(intToMiniRoman(94) === 'xciv')\n console.assert(intToMiniRoman(532) === 'dxxxii')\n console.assert(intToMiniRoman(900) === 'cm')\n console.assert(intToMiniRoman(994) === 'cmxciv')\n console.assert(intToMiniRoman(1000) === 'm')\n}\n\ntestIntToMiniRoman()\n", "declaration": "\nconst intToMiniRoman = (number) => {\n", "example_test": "const testIntToMiniRoman = () => {\n console.assert(intToMiniRoman(19) === 'xix')\n console.assert(intToMiniRoman(152) === 'clii')\n console.assert(intToMiniRoman(426) === 'cdxxvi')\n}\ntestIntToMiniRoman()\n", "buggy_solution": " let num = [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000]\n let sym = ['i', 'iv', 'v', 'ix', 'x', 'xl', 'l', 'xc', 'c', 'cd', 'd', 'cm', 'm']\n let i = 12\n let res = ''\n while (number) {\n let div = (number - number % num[i]) / num[i]\n while (div) {\n res += sym[i]\n div -= 1\n }\n i -= 1\n }\n return res\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "infinite loop", "entry_point": "intToMiniRoman", "signature": "const intToMiniRoman = (number)", "docstring": "Given a positive integer, obtain its roman numeral equivalent as a string,\nand return it in lowercase.\nRestrictions: 1 <= num <= 1000\nExamples:\n>>> intToMiniRoman(19) == 'xix'\n>>> intToMiniRoman(152) == 'clii'\n>>> intToMiniRoman(426) == 'cdxxvi'", "instruction": "Write a JavaScript function `const intToMiniRoman = (number)` to solve the following problem:\nGiven a positive integer, obtain its roman numeral equivalent as a string,\nand return it in lowercase.\nRestrictions: 1 <= num <= 1000\nExamples:\n>>> intToMiniRoman(19) == 'xix'\n>>> intToMiniRoman(152) == 'clii'\n>>> intToMiniRoman(426) == 'cdxxvi'"} +{"task_id": "JavaScript/157", "prompt": "/*\n Given the lengths of the three sides of a triangle. Return true if the three\n sides form a right-angled triangle, false otherwise.\n A right-angled triangle is a triangle in which one angle is right angle or\n 90 degree.\n Example:\n rightAngleTriangle(3, 4, 5) == true\n rightAngleTriangle(1, 2, 3) == false\n */\nconst rightAngleTriangle = (a, b, c) => {\n", "canonical_solution": " return (a * a + b * b == c * c || a * a == b * b + c * c || b * b == a * a + c * c)\n}\n\n", "test": "const testRightAngleTriangle = () => {\n console.assert(rightAngleTriangle(3, 4, 5) === true)\n console.assert(rightAngleTriangle(1, 2, 3) === false)\n console.assert(rightAngleTriangle(10, 6, 8) === true)\n console.assert(rightAngleTriangle(2, 2, 2) === false)\n console.assert(rightAngleTriangle(7, 24, 25) === true)\n console.assert(rightAngleTriangle(10, 5, 7) === false)\n console.assert(rightAngleTriangle(5, 12, 13) === true)\n console.assert(rightAngleTriangle(15, 8, 17) === true)\n console.assert(rightAngleTriangle(48, 55, 73) === true)\n console.assert(rightAngleTriangle(1, 1, 1) === false)\n console.assert(rightAngleTriangle(2, 2, 10) === false)\n}\n\ntestRightAngleTriangle()\n", "declaration": "\nconst rightAngleTriangle = (a, b, c) => {\n", "example_test": "const testRightAngleTriangle = () => {\n console.assert(rightAngleTriangle(3, 4, 5) === true)\n console.assert(rightAngleTriangle(1, 2, 3) === false)\n}\ntestRightAngleTriangle()\n", "buggy_solution": " return (a * a + b * b == c * c)\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "rightAngleTriangle", "signature": "const rightAngleTriangle = (a, b, c)", "docstring": "Given the lengths of the three sides of a triangle. Return true if the three\nsides form a right-angled triangle, false otherwise.\nA right-angled triangle is a triangle in which one angle is right angle or\n90 degree.\nExample:\nrightAngleTriangle(3, 4, 5) == true\nrightAngleTriangle(1, 2, 3) == false", "instruction": "Write a JavaScript function `const rightAngleTriangle = (a, b, c)` to solve the following problem:\nGiven the lengths of the three sides of a triangle. Return true if the three\nsides form a right-angled triangle, false otherwise.\nA right-angled triangle is a triangle in which one angle is right angle or\n90 degree.\nExample:\nrightAngleTriangle(3, 4, 5) == true\nrightAngleTriangle(1, 2, 3) == false"} +{"task_id": "JavaScript/158", "prompt": "/*Write a function that accepts a list of strings.\n The list contains different words. Return the word with maximum number\n of unique characters. If multiple strings have maximum number of unique\n characters, return the one which comes first in lexicographical order.\n\n findMax([\"name\", \"of\", \"string\"]) === \"string\"\n findMax([\"name\", \"enam\", \"game\"]) === \"enam\"\n findMax([\"aaaaaaa\", \"bb\" ,\"cc\"]) === \"\"aaaaaaa\"\n */\nconst findMax = (words) => {\n", "canonical_solution": " let s = -1\n let u = -1\n if (words.length == 0) { return '' }\n for (let i = 0; i < words.length; i++) {\n let p = 0\n for (let j = 0; j < words[i].length; j++) {\n let y = 1\n for (let k = 0; k < j; k++) {\n if (words[i][j] == words[i][k]) { y = 0 }\n }\n if (y == 1) { p++ }\n }\n if (p > s || (p == s && words[i] < words[u])) {\n u = i;\n s = p;\n }\n }\n return words[u]\n}\n\n", "test": "const testFindMax = () => {\n console.assert(findMax(['name', 'of', 'string']) === 'string')\n console.assert(findMax(['name', 'enam', 'game']) === 'enam')\n console.assert(findMax(['aaaaaaa', 'bb', 'cc']) === 'aaaaaaa')\n console.assert(findMax(['abc', 'cba']) === 'abc')\n console.assert(\n findMax(['play', 'this', 'game', 'of', 'footbott']) === 'footbott'\n )\n console.assert(findMax(['we', 'are', 'gonna', 'rock']) === 'gonna')\n console.assert(findMax(['we', 'are', 'a', 'mad', 'nation']) === 'nation')\n console.assert(findMax(['this', 'is', 'a', 'prrk']) === 'this')\n console.assert(findMax(['b']) === 'b')\n console.assert(findMax(['play', 'play', 'play']) === 'play')\n}\n\ntestFindMax()\n", "declaration": "\nconst findMax = (words) => {\n", "example_test": "const testFindMax = () => {\n console.assert(findMax(['name', 'of', 'string']) === 'string')\n console.assert(findMax(['name', 'enam', 'game']) === 'enam')\n console.assert(findMax(['aaaaaaa', 'bb', 'cc']) === 'aaaaaaa')\n}\ntestFindMax()\n", "buggy_solution": " let s = -1\n let u = -1\n if (words.length == 0) { return '' }\n for (let i = 0; i < words.length; i++) {\n let p = 0\n for (let j = 0; j < words[i].length; j++) {\n let y = 1\n for (let k = 0; k < j; k++) {\n if (words[i][j] == words[i][k]) { y = 0 }\n }\n }\n if (p > s || (p == s && words[i] < words[u])) {\n u = i;\n s = p;\n }\n }\n return words[u]\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "findMax", "signature": "const findMax = (words)", "docstring": "Write a function that accepts a list of strings.\nThe list contains different words. Return the word with maximum number\nof unique characters. If multiple strings have maximum number of unique\ncharacters, return the one which comes first in lexicographical order.\nfindMax([\"name\", \"of\", \"string\"]) === \"string\"\nfindMax([\"name\", \"enam\", \"game\"]) === \"enam\"\nfindMax([\"aaaaaaa\", \"bb\" ,\"cc\"]) === \"\"aaaaaaa\"", "instruction": "Write a JavaScript function `const findMax = (words)` to solve the following problem:\nWrite a function that accepts a list of strings.\nThe list contains different words. Return the word with maximum number\nof unique characters. If multiple strings have maximum number of unique\ncharacters, return the one which comes first in lexicographical order.\nfindMax([\"name\", \"of\", \"string\"]) === \"string\"\nfindMax([\"name\", \"enam\", \"game\"]) === \"enam\"\nfindMax([\"aaaaaaa\", \"bb\" ,\"cc\"]) === \"\"aaaaaaa\""} +{"task_id": "JavaScript/159", "prompt": "/*\n You're a hungry rabbit, and you already have eaten a certain number of carrots,\n but now you need to eat more carrots to complete the day's meals.\n you should return an array of [ total number of eaten carrots after your meals,\n the number of carrots left after your meals ]\n if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.\n \n Example:\n * eat(5, 6, 10) -> [11, 4]\n * eat(4, 8, 9) -> [12, 1]\n * eat(1, 10, 10) -> [11, 0]\n * eat(2, 11, 5) -> [7, 0]\n \n Variables:\n @number : integer\n the number of carrots that you have eaten.\n @need : integer\n the number of carrots that you need to eat.\n @remaining : integer\n the number of remaining carrots thet exist in stock\n \n Constrain:\n * 0 <= number <= 1000\n * 0 <= need <= 1000\n * 0 <= remaining <= 1000\n\n Have fun :)\n */\nconst eat = (number, need, remaining) => {\n", "canonical_solution": " if (need <= remaining) {\n return [need + number, remaining - need]\n }\n return [remaining + number, 0]\n}\n\n", "test": "const testEat = () => {\n console.assert(JSON.stringify(eat(5, 6, 10)) === JSON.stringify([11, 4]))\n console.assert(JSON.stringify(eat(4, 8, 9)) === JSON.stringify([12, 1]))\n console.assert(JSON.stringify(eat(1, 10, 10)) === JSON.stringify([11, 0]))\n console.assert(JSON.stringify(eat(2, 11, 5)) === JSON.stringify([7, 0]))\n console.assert(JSON.stringify(eat(4, 5, 7)) === JSON.stringify([9, 2]))\n console.assert(JSON.stringify(eat(4, 5, 1)) === JSON.stringify([5, 0]))\n}\n\ntestEat()\n", "declaration": "\nconst eat = (number, need, remaining) => {\n", "example_test": "const testEat = () => {\n console.assert(JSON.stringify(eat(5, 6, 10)) === JSON.stringify([11, 4]))\n console.assert(JSON.stringify(eat(4, 8, 9)) === JSON.stringify([12, 1]))\n console.assert(JSON.stringify(eat(1, 10, 10)) === JSON.stringify([11, 0]))\n console.assert(JSON.stringify(eat(2, 11, 5)) === JSON.stringify([7, 0]))\n}\ntestEat()\n", "buggy_solution": " if (need <= remaining) {\n return [need + number, number + remaining - need]\n }\n return [remaining + need + number, 0]\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "eat", "signature": "const eat = (number, need, remaining)", "docstring": "You're a hungry rabbit, and you already have eaten a certain number of carrots,\nbut now you need to eat more carrots to complete the day's meals.\nyou should return an array of [ total number of eaten carrots after your meals,\nthe number of carrots left after your meals ]\nif there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.\nExample:\n* eat(5, 6, 10) -> [11, 4]\n* eat(4, 8, 9) -> [12, 1]\n* eat(1, 10, 10) -> [11, 0]\n* eat(2, 11, 5) -> [7, 0]\nVariables:\n@number : integer\nthe number of carrots that you have eaten.\n@need : integer\nthe number of carrots that you need to eat.\n@remaining : integer\nthe number of remaining carrots thet exist in stock\nConstrain:\n* 0 <= number <= 1000\n* 0 <= need <= 1000\n* 0 <= remaining <= 1000\nHave fun :)", "instruction": "Write a JavaScript function `const eat = (number, need, remaining)` to solve the following problem:\nYou're a hungry rabbit, and you already have eaten a certain number of carrots,\nbut now you need to eat more carrots to complete the day's meals.\nyou should return an array of [ total number of eaten carrots after your meals,\nthe number of carrots left after your meals ]\nif there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.\nExample:\n* eat(5, 6, 10) -> [11, 4]\n* eat(4, 8, 9) -> [12, 1]\n* eat(1, 10, 10) -> [11, 0]\n* eat(2, 11, 5) -> [7, 0]\nVariables:\n@number : integer\nthe number of carrots that you have eaten.\n@need : integer\nthe number of carrots that you need to eat.\n@remaining : integer\nthe number of remaining carrots thet exist in stock\nConstrain:\n* 0 <= number <= 1000\n* 0 <= need <= 1000\n* 0 <= remaining <= 1000\nHave fun :)"} +{"task_id": "JavaScript/160", "prompt": "/*\n Given two lists operator, and operand. The first list has basic algebra operations, and \n the second list is a list of integers. Use the two given lists to build the algebric \n expression and return the evaluation of this expression.\n\n The basic algebra operations:\n Addition ( + ) \n Subtraction ( - ) \n Multiplication ( * ) \n Floor division ( // ) \n Exponentiation ( ** ) \n\n Example:\n operator['+', '*', '-']\n array = [2, 3, 4, 5]\n result = 2 + 3 * 4 - 5\n => result = 9\n\n Note:\n The length of operator list is equal to the length of operand list minus one.\n Operand is a list of of non-negative integers.\n Operator list has at least one operator, and operand list has at least two operands.\n\n */\nconst doAlgebra = (operator, operand) => {\n", "canonical_solution": " while (operator.length > 0) {\n let y = 0\n for (let i = operator.length - 1; i >= 0; i--) {\n if (operator[i] == '**') {\n let u = operand[i]\n while (operand[i + 1] > 1) {\n operand[i + 1]--;\n operand[i] *= u;\n }\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n for (let i = 0; i < operator.length; i++) {\n if (operator[i] == '*') {\n operand[i] *= operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n else if (operator[i] == '//') {\n operand[i] = (operand[i] - operand[i] % operand[i + 1]) / operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n for (let i = 0; i < operator.length; i++) {\n if (operator[i] == '+') {\n operand[i] += operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n else if (operator[i] == '-') {\n operand[i] -= operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n }\n return operand[0]\n}\n\n", "test": "const testDoAlgebra = () => {\n console.assert(doAlgebra(['**', '*', '+'], [2, 3, 4, 5]) === 37)\n console.assert(doAlgebra(['+', '*', '-'], [2, 3, 4, 5]) === 9)\n console.assert(doAlgebra(['//', '*'], [7, 3, 4]) === 8)\n}\n\ntestDoAlgebra()\n", "declaration": "\nconst doAlgebra = (operator, operand) => {\n", "example_test": "", "buggy_solution": " while (operator.length > 0) {\n let y = 0\n for (let i = operator.length - 1; i >= 0; i--) {\n if (operator[i] == '**') {\n let u = operand[i]\n while (operand[i + 1] > 1) {\n operand[i + 1]--;\n operand[i] *= u;\n }\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n for (let i = 0; i < operator.length; i++) {\n if (operator[i] == '*') {\n operand[i] *= operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n else if (operator[i] == '//') {\n operand[i] = (operand[i + 1] - operand[i] % operand[i + 1]) / operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n for (let i = 0; i < operator.length; i++) {\n if (operator[i] == '+') {\n operand[i] += operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n else if (operator[i] == '-') {\n operand[i] -= operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n }\n return operand[0]\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "doAlgebra", "signature": "const doAlgebra = (operator, operand)", "docstring": "Given two lists operator, and operand. The first list has basic algebra operations, and\nthe second list is a list of integers. Use the two given lists to build the algebric\nexpression and return the evaluation of this expression.\nThe basic algebra operations:\nAddition ( + )\nSubtraction ( - )\nMultiplication ( * )\nFloor division ( // )\nExponentiation ( ** )\nExample:\noperator['+', '*', '-']\narray = [2, 3, 4, 5]\nresult = 2 + 3 * 4 - 5\n=> result = 9\nNote:\nThe length of operator list is equal to the length of operand list minus one.\nOperand is a list of of non-negative integers.\nOperator list has at least one operator, and operand list has at least two operands.", "instruction": "Write a JavaScript function `const doAlgebra = (operator, operand)` to solve the following problem:\nGiven two lists operator, and operand. The first list has basic algebra operations, and\nthe second list is a list of integers. Use the two given lists to build the algebric\nexpression and return the evaluation of this expression.\nThe basic algebra operations:\nAddition ( + )\nSubtraction ( - )\nMultiplication ( * )\nFloor division ( // )\nExponentiation ( ** )\nExample:\noperator['+', '*', '-']\narray = [2, 3, 4, 5]\nresult = 2 + 3 * 4 - 5\n=> result = 9\nNote:\nThe length of operator list is equal to the length of operand list minus one.\nOperand is a list of of non-negative integers.\nOperator list has at least one operator, and operand list has at least two operands."} +{"task_id": "JavaScript/161", "prompt": "/*You are given a string s.\n if s[i] is a letter, reverse its case from lower to upper or vise versa, \n otherwise keep it as it is.\n If the string contains no letters, reverse the string.\n The function should return the resulted string.\n Examples\n solve(\"1234\") = \"4321\"\n solve(\"ab\") = \"AB\"\n solve(\"#a@C\") = \"#A@c\"\n */\nconst solve = (s) => {\n", "canonical_solution": " let t = 0\n let p = ''\n for (let i = 0; i < s.length; i++) {\n let y = s[i].charCodeAt()\n if (y >= 65 && y <= 90) {\n y += 32;\n t = 1;\n } else if (y >= 97 && y <= 122) {\n y -= 32;\n t = 1;\n }\n p += String.fromCharCode(y)\n }\n if (t == 1) { return p }\n let u = ''\n for (let i = 0; i < p.length; i++) {\n u += p[p.length - i - 1]\n }\n return u\n}\n\n", "test": "const testSolve = () => {\n console.assert(solve('AsDf') === 'aSdF')\n console.assert(solve('1234') === '4321')\n console.assert(solve('ab') === 'AB')\n console.assert(solve('#a@C') === '#A@c')\n console.assert(solve('#AsdfW^45') === '#aSDFw^45')\n console.assert(solve('#6@2') === '2@6#')\n console.assert(solve('#$a^D') === '#$A^d')\n console.assert(solve('#ccc') === '#CCC')\n}\n\ntestSolve()\n", "declaration": "\nconst solve = (s) => {\n", "example_test": "const testSolve = () => {\n console.assert(solve('1234') === '4321')\n console.assert(solve('ab') === 'AB')\n console.assert(solve('#a@C') === '#A@c')\n}\ntestSolve()\n", "buggy_solution": " let t = 0\n let p = ''\n for (let i = 0; i < s.length; i++) {\n let y = s[i].charCodeAt()\n if (y >= 65 && y <= 90) {\n y += 32;\n t = 1;\n }\n p += String.fromCharCode(y)\n }\n if (t == 1) { return p }\n let u = ''\n for (let i = 0; i < p.length; i++) {\n u += p[p.length - i - 1]\n }\n return u\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "solve", "signature": "const solve = (s)", "docstring": "You are given a string s.\nif s[i] is a letter, reverse its case from lower to upper or vise versa,\notherwise keep it as it is.\nIf the string contains no letters, reverse the string.\nThe function should return the resulted string.\nExamples\nsolve(\"1234\") = \"4321\"\nsolve(\"ab\") = \"AB\"\nsolve(\"#a@C\") = \"#A@c\"", "instruction": "Write a JavaScript function `const solve = (s)` to solve the following problem:\nYou are given a string s.\nif s[i] is a letter, reverse its case from lower to upper or vise versa,\notherwise keep it as it is.\nIf the string contains no letters, reverse the string.\nThe function should return the resulted string.\nExamples\nsolve(\"1234\") = \"4321\"\nsolve(\"ab\") = \"AB\"\nsolve(\"#a@C\") = \"#A@c\""} +{"task_id": "JavaScript/162", "prompt": "/*\n Given a string 'text', return its md5 hash equivalent string.\n If 'text' is an empty string, return null.\n\n >>> stringToMd5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'\n */\nconst stringToMd5 = (text) => {\n", "canonical_solution": " if (text == '') { return null }\n var md5 = require('js-md5')\n return md5(text)\n}\n\n", "test": "const testStringToMd5 = () => {\n console.assert(\n stringToMd5('Hello world') === '3e25960a79dbc69b674cd4ec67a72c62'\n )\n console.assert(stringToMd5('') === null)\n console.assert(stringToMd5('A B C') === '0ef78513b0cb8cef12743f5aeb35f888')\n console.assert(stringToMd5('password') === '5f4dcc3b5aa765d61d8327deb882cf99')\n}\n\ntestStringToMd5()\n", "declaration": "\nconst stringToMd5 = (text) => {\n", "example_test": "const testStringToMd5 = () => {\n console.assert(\n stringToMd5('Hello world') === '3e25960a79dbc69b674cd4ec67a72c62'\n )\n}\ntestStringToMd5()\n", "buggy_solution": " if (text == '') { return null }\n var md5 = require('js-md5')\n return md5('text')\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "stringToMd5", "signature": "const stringToMd5 = (text)", "docstring": "Given a string 'text', return its md5 hash equivalent string.\nIf 'text' is an empty string, return null.\n>>> stringToMd5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'", "instruction": "Write a JavaScript function `const stringToMd5 = (text)` to solve the following problem:\nGiven a string 'text', return its md5 hash equivalent string.\nIf 'text' is an empty string, return null.\n>>> stringToMd5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'"} +{"task_id": "JavaScript/163", "prompt": "/*\n Given two positive integers a and b, return the even digits between a\n and b, in ascending order.\n\n For example:\n generateIntegers(2, 8) => [2, 4, 6, 8]\n generateIntegers(8, 2) => [2, 4, 6, 8]\n generateIntegers(10, 14) => []\n */\nconst generateIntegers = (a, b) => {\n", "canonical_solution": " if (a > b) {\n let tmp = a;\n a = b;\n b = tmp;\n }\n let y = []\n for (let i = a; i <= b; i++) {\n if (i == 2 || i == 4 || i == 6 || i == 8) { y.push(i) }\n }\n return y\n}\n\n", "test": "const testGenerateIntegers = () => {\n console.assert(\n JSON.stringify(generateIntegers(2, 10)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(10, 2)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(132, 2)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(17, 89)) === JSON.stringify([])\n )\n}\n\ntestGenerateIntegers()\n", "declaration": "\nconst generateIntegers = (a, b) => {\n", "example_test": "const testGenerateIntegers = () => {\n console.assert(\n JSON.stringify(generateIntegers(2, 8)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(8, 2)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(10, 14)) === JSON.stringify([])\n )\n}\ntestGenerateIntegers()\n", "buggy_solution": " if (a > b) {\n let tmp = a;\n a = b;\n b = tmp;\n }\n let y = []\n for (let i = a; i > b; i++) {\n if (i == 2 || i == 4 || i == 6 || i == 8) { y.push(i) }\n }\n return y\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "generateIntegers", "signature": "const generateIntegers = (a, b)", "docstring": "Given two positive integers a and b, return the even digits between a\nand b, in ascending order.\nFor example:\ngenerateIntegers(2, 8) => [2, 4, 6, 8]\ngenerateIntegers(8, 2) => [2, 4, 6, 8]\ngenerateIntegers(10, 14) => []", "instruction": "Write a JavaScript function `const generateIntegers = (a, b)` to solve the following problem:\nGiven two positive integers a and b, return the even digits between a\nand b, in ascending order.\nFor example:\ngenerateIntegers(2, 8) => [2, 4, 6, 8]\ngenerateIntegers(8, 2) => [2, 4, 6, 8]\ngenerateIntegers(10, 14) => []"}