diff --git "a/data/js/data/humanevalbugs.jsonl" "b/data/js/data/humanevalbugs.jsonl" new file mode 100644--- /dev/null +++ "b/data/js/data/humanevalbugs.jsonl" @@ -0,0 +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 = 1, result = [];\n for (const n of numbers) {\n running_max = Math.max(running_max, n);\n result.push(running_max);\n }\n return result;\n}\n\n", "bug_type": "value 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}\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, begin) > 0)\n begin = center;\n else\n end = center;\n }\n return begin;\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 Array.from(new Set(l));\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 = 0; i < l.length; i++)\n for (let j = i + 1; j < l.length; j++)\n for (let k = i + 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": "variable 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 if (e1 == e2)\n ret.add(e1);\n return [...ret];\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; j++)\n if (n % j == 0 && isPrime(j))\n largest = Math.max(largest, j);\n return largest;\n}\n\n", "bug_type": "value 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[1] == ' ' && S[0] == '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 * z === y || x === y * z || x + y === z || x + z === y || x === y + z || x - y === z || x - z === y || x === y - z)) {\n return true\n }\n return false\n}\n\n", "bug_type": "excess 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": "excess logic", "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 z = 1\n for (let i = 0; i < t.length; i++) {\n if (t[i] != t[t.length - i - 1]) {\n z = 0\n }\n }\n if (z == 0) {\n return (z, false)\n }\n return (z, true)\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 z = 1\n for (let i = 0; i < t.length; i++) {\n if (t[i] != t[t.length - i - 1]) {\n z = 0\n }\n }\n if (z == 0) {\n return (z, true)\n }\n return (z, false)\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 = 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 + 1 }\n }\n }\n return min\n}\n\n", "bug_type": "excess logic", "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[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 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}\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 'yes' }\n return 'no'\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 - lo }\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 * 2\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", "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 >= 65 && y <= 122) || (y >= 90 && y <= 97)) { return true }\n return false\n }\n if (txt[len - 2] == ' ' && ((y >= 90 && y <= 97) || (y >= 65 && y <= 122))) { 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 && lst[i] > b) { b = a }\n if (lst[i] < b && lst[i] > a) { 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}\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] * 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 guess[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; i++) {\n for (let j = 0; j < l; 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": "missing logic", "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 || b * b == a * a + 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": "value 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"}