diff --git "a/data/js/data/humanevalbugs.jsonl" "b/data/js/data/humanevalbugs.jsonl" --- "a/data/js/data/humanevalbugs.jsonl" +++ "b/data/js/data/humanevalbugs.jsonl" @@ -7,7 +7,7 @@ {"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/9", "prompt": "/* From a given list of integers, generate a list of rolling maximum element found until given moment\n in the sequence.\n >>> rollingMax([1, 2, 3, 2, 3, 4, 2])\n [1, 2, 3, 3, 3, 4, 4]\n */\nconst rollingMax = (numbers) => {\n", "canonical_solution": " var running_max, result = [];\n for (const n of numbers) {\n if (running_max == undefined)\n running_max = n;\n else\n running_max = Math.max(running_max, n);\n result.push(running_max);\n }\n return result;\n}\n\n", "test": "const testRollingMax = () => {\n console.assert(JSON.stringify(rollingMax([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(rollingMax([1, 2, 3, 4])) === JSON.stringify([1, 2, 3, 4])\n )\n console.assert(\n JSON.stringify(rollingMax([4, 3, 2, 1])) === JSON.stringify([4, 4, 4, 4])\n )\n console.assert(\n JSON.stringify(\n rollingMax([3, 2, 3, 100, 3])) === JSON.stringify([3, 3, 3, 100, 100])\n )\n}\n\ntestRollingMax()\n", "declaration": "\nconst rollingMax = (numbers) => {\n", "example_test": "const testRollingMax = () => {\n console.assert(JSON.stringify(rollingMax([1, 2, 3, 2, 3, 4, 2])) === JSON.stringify([1, 2, 3, 3, 3, 4, 4]))\n}\ntestRollingMax()\n", "buggy_solution": " var running_max, result = [];\n for (const n of numbers) {\n if (running_max == undefined)\n running_max = n;\n else\n running_max = Math.max(numbers);\n result.push(running_max);\n }\n return result;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "RollingMax"} {"task_id": "JavaScript/10", "prompt": "/* Test if gniven strig is a palindrome */\nconst isPalindrome = (string) => {\n return string == string.split('').reverse().join('');\n}\n\n/* Find the shortest palindrome that begins with a supplied string.\n Algorithm idea is simple:\n - Find the longest postfix of supplied string that is a palindrome.\n - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.\n >>> makePalindrome('')\n ''\n >>> makePalindrome('cat')\n 'catac'\n >>> makePalindrome('cata')\n 'catac'\n */\nconst makePalindrome = (string) => {\n", "canonical_solution": " if (string == '')\n return '';\n var beginning_of_suffix = 0;\n while (!isPalindrome(string.slice(beginning_of_suffix)))\n beginning_of_suffix += 1;\n return string + string.slice(0, beginning_of_suffix).split('').reverse().join('');\n}\n\n", "test": "const testmakePalindrome = () => {\n console.assert(makePalindrome('') === '')\n console.assert(makePalindrome('x') === 'x')\n console.assert(makePalindrome('xyz') === 'xyzyx')\n console.assert(makePalindrome('xyx') === 'xyx')\n console.assert(makePalindrome('jerry') === 'jerryrrej')\n}\n\ntestmakePalindrome()\n", "declaration": "const isPalindrome = (string) => {\n return string == string.split('').reverse().join('');\n}\n\nconst makePalindrome = (string) => {\n", "example_test": "const testmakePalindrome = () => {\n console.assert(makePalindrome('') === '')\n console.assert(makePalindrome('cat') === 'catac')\n console.assert(makePalindrome('cata') === 'catac')\n}\ntestmakePalindrome()\n", "buggy_solution": " if (string == '')\n return '';\n var beginning_of_suffix = 0;\n while (!isPalindrome(string))\n beginning_of_suffix += 1;\n return string + string.slice(0, beginning_of_suffix).split('').reverse().join('');\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "stackoverflow", "entry_point": "MakePalindrome"} {"task_id": "JavaScript/11", "prompt": "/* Input are two strings a and b consisting only of 1s and 0s.\n Perform binary XOR on these inputs and return result also as a string.\n >>> stringXor('010', '110')\n '100'\n */\nconst stringXor = (a, b) => {\n", "canonical_solution": " var xor = function (i, j) {\n if (i == j)\n return '0';\n else\n return '1';\n }\n return a.split('').map((item, index) => xor(item, b[index])).join('');\n}\n\n", "test": "const testStringXor = () => {\n console.assert(stringXor('111000', '101010') === '010010')\n console.assert(stringXor('1', '1') === '0')\n console.assert(stringXor('0101', '0000') === '0101')\n}\n\ntestStringXor()\n", "declaration": "\nconst stringXor = (a, b) => {\n", "example_test": "const testStringXor = () => {\n console.assert(stringXor('010', '110') === '100')\n}\ntestStringXor()\n", "buggy_solution": " var xor = function (i, j) {\n if (i == j)\n return '1';\n else\n return '0';\n }\n return a.split('').map((item, index) => xor(item, b[index])).join('');\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "StringXor"} {"task_id": "JavaScript/12", "prompt": "/* Out of list of strings, return the longest one. Return the first one in case of multiple\n strings of the same length. Return null in case the input list is empty.\n >>> longest([])\n\n >>> longest(['a', 'b', 'c'])\n 'a'\n >>> longest(['a', 'bb', 'ccc'])\n 'ccc'\n */\nconst longest = (strings) => {\n", "canonical_solution": " if (!Array.isArray(strings) || strings.length == 0)\n return null;\n var maxlen = Math.max(...strings.map(x => x.length));\n for (const s of strings) {\n if (s.length == maxlen) {\n return s;\n }\n }\n}\n\n", "test": "const testLongest = () => {\n console.assert(longest([]) === null)\n console.assert(longest(['x', 'y', 'z']) === 'x')\n console.assert(longest(['x', 'yyy', 'zzzz', 'www', 'kkkk', 'abc']) === 'zzzz')\n}\n\ntestLongest()\n", "declaration": "\nconst longest = (strings) => {\n", "example_test": "const testLongest = () => {\n console.assert(longest([]) === null)\n console.assert(longest(['a', 'b', 'c']) === 'a')\n console.assert(longest(['a', 'bb', 'ccc']) === 'ccc')\n}\ntestLongest()\n", "buggy_solution": " if (!Array.isArray(strings) || strings.length == 0)\n return null;\n var maxlen = Math.max(...strings.map(x => x.length));\n for (const s of strings) {\n if (s.length > maxlen) {\n return s;\n }\n }\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "Longest"} @@ -32,13 +32,13 @@ {"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/34", "prompt": "/*Return sorted unique elements in a list\n >>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123])\n [0, 2, 3, 5, 9, 123]\n */\nconst unique = (l) => {\n", "canonical_solution": " return Array.from(new Set(l)).sort((a, b) => (a - b));\n}\n\n", "test": "const testUnique = () => {\n console.assert(\n JSON.stringify(unique([5, 3, 5, 2, 3, 3, 9, 0, 123])) ===\n JSON.stringify([0, 2, 3, 5, 9, 123])\n )\n}\n\ntestUnique()\n", "declaration": "\nconst unique = (l) => {\n", "example_test": "const testUnique = () => {\n console.assert(\n JSON.stringify(unique([5, 3, 5, 2, 3, 3, 9, 0, 123])) ===\n JSON.stringify([0, 2, 3, 5, 9, 123])\n )\n}\ntestUnique()\n", "buggy_solution": " return l.sort((a, b) => (a - b));\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "Unique"} {"task_id": "JavaScript/35", "prompt": "/*Return maximum element in the list.\n >>> maxElement([1, 2, 3])\n 3\n >>> maxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n 123\n */\nconst maxElement = (l) => {\n", "canonical_solution": " return Math.max(...l);\n}\n\n", "test": "const testMaxElement = () => {\n console.assert(maxElement([1, 2, 3]) === 3)\n console.assert(maxElement([5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10]) === 124)\n}\n\ntestMaxElement()\n", "declaration": "\nconst maxElement = (l) => {\n", "example_test": "const testMaxElement = () => {\n console.assert(maxElement([1, 2, 3]) === 3)\n console.assert(maxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) === 123)\n}\ntestMaxElement()\n", "buggy_solution": " return Math.min(...l);\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "MaxElement"} {"task_id": "JavaScript/36", "prompt": "/*Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.\n >>> fizzBuzz(50)\n 0\n >>> fizzBuzz(78)\n 2\n >>> fizzBuzz(79)\n 3\n */\nconst fizzBuzz = (n) => {\n", "canonical_solution": " var ns = [], ans = 0;\n for (let i = 0; i < n; i++)\n if (i % 11 == 0 || i % 13 == 0)\n ns.push(i);\n var s = ns.map(x => x.toString()).join('');\n for (const c of s)\n ans += (c == '7');\n return ans;\n}\n\n", "test": "const testFizzBuzz = () => {\n console.assert(fizzBuzz(50) === 0)\n console.assert(fizzBuzz(78) === 2)\n console.assert(fizzBuzz(79) === 3)\n console.assert(fizzBuzz(100) === 3)\n console.assert(fizzBuzz(200) === 6)\n console.assert(fizzBuzz(4000) === 192)\n console.assert(fizzBuzz(10000) === 639)\n console.assert(fizzBuzz(100000) === 8026)\n}\n\ntestFizzBuzz()\n", "declaration": "\nconst fizzBuzz = (n) => {\n", "example_test": "const testFizzBuzz = () => {\n console.assert(fizzBuzz(50) === 0)\n console.assert(fizzBuzz(78) === 2)\n console.assert(fizzBuzz(79) === 3)\n}\ntestFizzBuzz()\n", "buggy_solution": " var ns = [], ans = 0;\n for (let i = 0; i < n; i++)\n if (i % 11 == 0 && i % 13 == 0)\n ns.push(i);\n var s = ns.map(x => x.toString()).join('');\n for (const c of s)\n ans += (c == '7');\n return ans;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "FizzBuzz"} {"task_id": "JavaScript/37", "prompt": "/*This function takes a list l and returns a list l' such that\n l' is identical to l in the odd indicies, while its values at the even indicies are equal\n to the values of the even indicies of l, but sorted.\n >>> sortEven([1, 2, 3])\n [1, 2, 3]\n >>> sortEven([5, 6, 3, 4])\n [3, 6, 5, 4]\n */\nconst sortEven = (l) => {\n", "canonical_solution": " var even = l.filter((item, index) => index % 2 == 0);\n even.sort((a, b) => (a - b));\n return l.map((item, index) => (index % 2 == 0 ? even[index / 2] : item));\n}\n\n", "test": "const testSortEven = () => {\n console.assert(JSON.stringify(sortEven([1, 2, 3])) ===\n JSON.stringify([1, 2, 3]))\n console.assert(JSON.stringify(\n sortEven([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) ===\n JSON.stringify([-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123]))\n console.assert(JSON.stringify(\n sortEven([5, 8, -12, 4, 23, 2, 3, 11, 12, -10])) ===\n JSON.stringify([-12, 8, 3, 4, 5, 2, 12, 11, 23, -10]))\n}\n\ntestSortEven()\n", "declaration": "\nconst sortEven = (l) => {\n", "example_test": "const testSortEven = () => {\n console.assert(JSON.stringify(sortEven([1, 2, 3])) ===\n JSON.stringify([1, 2, 3]))\n console.assert(JSON.stringify(\n sortEven([5,6,3,4])) ===\n JSON.stringify([3,6,5,4]))\n}\ntestSortEven()\n", "buggy_solution": " var even = l.filter((item, index) => index % 2 == 0);\n l.sort((a, b) => (a - b));\n return l.map((item, index) => (index % 2 == 0 ? even[index / 2] : item));\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "SortEven"} {"task_id": "JavaScript/38", "prompt": "/*\n returns encoded string by cycling groups of three characters.\n */\nconst encodeCyclic = (s) => {\n var groups = [], groups2 = [];\n for (let i = 0; i < Math.floor((s.length + 2) / 3); i++) {\n groups.push(s.slice(3 * i, Math.min((3 * i + 3), s.length)));\n }\n for (const group of groups) {\n if (group.length == 3)\n groups2.push(group.slice(1) + group[0]);\n else\n groups2.push(group);\n }\n return groups2.join('');\n}\n\n/*\n takes as input string encoded with encode_cyclic function. Returns decoded string.\n */\nconst decodeCyclic = (s) => {\n", "canonical_solution": " return encodeCyclic(encodeCyclic(s));\n}\n\n", "test": "const testDecodeCyclic = () => {\n const letters = new Array(26)\n .fill(null)\n .map((v, i) => String.fromCharCode(97 + i));\n\n for (let i = 0; i < 100; i++) {\n let str = new Array(Math.floor(Math.random() * 20)).fill(null);\n str = str.map(item => letters[Math.floor(Math.random() * letters.length)]).join('');\n let encoded_str = encodeCyclic(str);\n console.assert(decodeCyclic(encoded_str) === str);\n }\n}\n\ntestDecodeCyclic()\n", "declaration": "const encodeCyclic = (s) => {\n var groups = [], groups2 = [];\n for (let i = 0; i < Math.floor((s.length + 2) / 3); i++) {\n groups.push(s.slice(3 * i, Math.min((3 * i + 3), s.length)));\n }\n for (const group of groups) {\n if (group.length == 3)\n groups2.push(group.slice(1) + group[0]);\n else\n groups2.push(group);\n }\n return groups2.join('');\n}\n\nconst decodeCyclic = (s) => {\n", "example_test": "", "buggy_solution": " return encodeCyclic(s);\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "DecodeCyclic"} {"task_id": "JavaScript/39", "prompt": "/*\n primeFib returns n-th number that is a Fibonacci number and it's also prime.\n >>> primeFib(1)\n 2\n >>> primeFib(2)\n 3\n >>> primeFib(3)\n 5\n >>> primeFib(4)\n 13\n >>> primeFib(5)\n 89\n */\nconst primeFib = (n) => {\n", "canonical_solution": " var isPrime = function (p) {\n if (p < 2)\n return false;\n for (let k = 2; k < Math.min(Math.floor(Math.sqrt(p)) + 1, p - 1); k++) {\n if (p % k == 0)\n return false;\n }\n return true;\n }\n\n var f = [0, 1];\n while (true) {\n f.push(f.at(-1) + f.at(-2));\n if (isPrime(f.at(-1)))\n n -= 1;\n if (n == 0)\n return f.at(-1);\n }\n}\n\n", "test": "const testPrimeFib = () => {\n console.assert(primeFib(1) === 2)\n console.assert(primeFib(2) === 3)\n console.assert(primeFib(3) === 5)\n console.assert(primeFib(4) === 13)\n console.assert(primeFib(5) === 89)\n console.assert(primeFib(6) === 233)\n console.assert(primeFib(7) === 1597)\n console.assert(primeFib(8) === 28657)\n console.assert(primeFib(9) === 514229)\n console.assert(primeFib(10) === 433494437)\n}\n\ntestPrimeFib()\n", "declaration": "\nconst primeFib = (n) => {\n", "example_test": "const testPrimeFib = () => {\n console.assert(primeFib(1) === 2)\n console.assert(primeFib(2) === 3)\n console.assert(primeFib(3) === 5)\n console.assert(primeFib(4) === 13)\n console.assert(primeFib(5) === 89)\n}\ntestPrimeFib()\n", "buggy_solution": " var isPrime = function (p) {\n if (p < 2)\n return false;\n for (let k = 2; k < Math.min(Math.floor(Math.sqrt(p)), p); k++) {\n if (p % k == 0)\n return false;\n }\n return true;\n }\n\n var f = [0, 1];\n while (true) {\n f.push(f.at(-1) + f.at(-2));\n if (isPrime(f.at(-1)))\n n -= 1;\n if (n == 0)\n return f.at(-1);\n }\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "PrimeFib"} -{"task_id": "JavaScript/40", "prompt": "/*\n triplesSumToZero takes a list of integers as an input.\n it returns true if there are three distinct elements in the list that\n sum to zero, and false otherwise.\n\n >>> triplesSumToZero([1, 3, 5, 0])\n false\n >>> triplesSumToZero([1, 3, -2, 1])\n true\n >>> triplesSumToZero([1, 2, 3, 7])\n false\n >>> triplesSumToZero([2, 4, -5, 3, 9, 7])\n true\n >>> triplesSumToZero([1])\n false\n */\nconst triplesSumToZero = (l) => {\n", "canonical_solution": " for (let i = 0; i < l.length; i++)\n for (let j = i + 1; j < l.length; j++)\n for (let k = j + 1; k < l.length; k++)\n if (l[i] + l[j] + l[k] == 0)\n return true;\n return false;\n}\n\n", "test": "const testTriplesSumToZero = () => {\n console.assert(triplesSumToZero([1, 3, 5, 0]) === false)\n console.assert(triplesSumToZero([1, 3, 5, -1]) === false)\n console.assert(triplesSumToZero([1, 3, -2, 1]) === true)\n console.assert(triplesSumToZero([1, 2, 3, 7]) === false)\n console.assert(triplesSumToZero([1, 2, 5, 7]) === false)\n console.assert(triplesSumToZero([2, 4, -5, 3, 9, 7]) === true)\n console.assert(triplesSumToZero([1]) === false)\n console.assert(triplesSumToZero([1, 3, 5, -100]) === false)\n console.assert(triplesSumToZero([100, 3, 5, -100]) === false)\n}\n\ntestTriplesSumToZero()\n", "declaration": "\nconst triplesSumToZero = (l) => {\n", "example_test": "const testTriplesSumToZero = () => {\n console.assert(triplesSumToZero([1, 3, 5, 0]) === false)\n console.assert(triplesSumToZero([1, 3, -2, 1]) === true)\n console.assert(triplesSumToZero([1, 2, 3, 7]) === false)\n console.assert(triplesSumToZero([2, 4, -5, 3, 9, 7]) === true)\n}\ntestTriplesSumToZero()\n", "buggy_solution": " for (let i = 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/40", "prompt": "/*\n triplesSumToZero takes a list of integers as an input.\n it returns true if there are three distinct elements in the list that\n sum to zero, and false otherwise.\n\n >>> triplesSumToZero([1, 3, 5, 0])\n false\n >>> triplesSumToZero([1, 3, -2, 1])\n true\n >>> triplesSumToZero([1, 2, 3, 7])\n false\n >>> triplesSumToZero([2, 4, -5, 3, 9, 7])\n true\n >>> triplesSumToZero([1])\n false\n */\nconst triplesSumToZero = (l) => {\n", "canonical_solution": " for (let i = 0; i < l.length; i++)\n for (let j = i + 1; j < l.length; j++)\n for (let k = j + 1; k < l.length; k++)\n if (l[i] + l[j] + l[k] == 0)\n return true;\n return false;\n}\n\n", "test": "const testTriplesSumToZero = () => {\n console.assert(triplesSumToZero([1, 3, 5, 0]) === false)\n console.assert(triplesSumToZero([1, 3, 5, -1]) === false)\n console.assert(triplesSumToZero([1, 3, -2, 1]) === true)\n console.assert(triplesSumToZero([1, 2, 3, 7]) === false)\n console.assert(triplesSumToZero([1, 2, 5, 7]) === false)\n console.assert(triplesSumToZero([2, 4, -5, 3, 9, 7]) === true)\n console.assert(triplesSumToZero([1]) === false)\n console.assert(triplesSumToZero([1, 3, 5, -100]) === false)\n console.assert(triplesSumToZero([100, 3, 5, -100]) === false)\n}\n\ntestTriplesSumToZero()\n", "declaration": "\nconst triplesSumToZero = (l) => {\n", "example_test": "const testTriplesSumToZero = () => {\n console.assert(triplesSumToZero([1, 3, 5, 0]) === false)\n console.assert(triplesSumToZero([1, 3, -2, 1]) === true)\n console.assert(triplesSumToZero([1, 2, 3, 7]) === false)\n console.assert(triplesSumToZero([2, 4, -5, 3, 9, 7]) === true)\n}\ntestTriplesSumToZero()\n", "buggy_solution": " for (let i = 1; i < l.length; i++)\n for (let j = i + 1; j < l.length; j++)\n for (let k = j + 1; k < l.length; k++)\n if (l[i] + l[j] + l[k] == 0)\n return true;\n return false;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "TriplesSumToZero"} {"task_id": "JavaScript/41", "prompt": "/*\n Imagine a road that's a perfectly straight infinitely long line.\n n cars are driving left to right; simultaneously, a different set of n cars\n are driving right to left. The two sets of cars start out being very far from\n each other. All cars move in the same speed. Two cars are said to collide\n when a car that's moving left to right hits a car that's moving right to left.\n However, the cars are infinitely sturdy and strong; as a result, they continue moving\n in their trajectory as if they did not collide.\n\n This function outputs the number of such collisions.\n */\nconst carRaceCollision = (n) => {\n", "canonical_solution": " return Math.pow(n, 2);\n}\n\n", "test": "const testCarRaceCollision = () => {\n console.assert(carRaceCollision(2) === 4)\n console.assert(carRaceCollision(3) === 9)\n console.assert(carRaceCollision(4) === 16)\n console.assert(carRaceCollision(8) === 64)\n console.assert(carRaceCollision(10) === 100)\n}\n\ntestCarRaceCollision()\n", "declaration": "\nconst carRaceCollision = (n) => {\n", "example_test": "", "buggy_solution": " return Math.pow(n, 3);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "CarRaceCollision"} {"task_id": "JavaScript/42", "prompt": "/*Return list with elements incremented by 1.\n >>> incrList([1, 2, 3])\n [2, 3, 4]\n >>> incrList([5, 3, 5, 2, 3, 3, 9, 0, 123])\n [6, 4, 6, 3, 4, 4, 10, 1, 124]\n */\nconst incrList = (l) => {\n", "canonical_solution": " return l.map(e => e + 1);\n}\n\n", "test": "const testIncrList = () => {\n console.assert(JSON.stringify(incrList([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(incrList([3, 2, 1])) === JSON.stringify([4, 3, 2])\n )\n console.assert(\n JSON.stringify(incrList([5, 2, 5, 2, 3, 3, 9, 0, 123])) ===\n JSON.stringify([6, 3, 6, 3, 4, 4, 10, 1, 124])\n )\n}\n\ntestIncrList()\n", "declaration": "\nconst incrList = (l) => {\n", "example_test": "const testIncrList = () => {\n console.assert(\n JSON.stringify(incrList([1, 2, 3])) === JSON.stringify([2, 3, 4])\n )\n console.assert(\n JSON.stringify(incrList([5, 2, 5, 2, 3, 3, 9, 0, 123])) ===\n JSON.stringify([6, 3, 6, 3, 4, 4, 10, 1, 124])\n )\n}\ntestIncrList()\n", "buggy_solution": " return l.map(e => e + 2);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "IncrList"} {"task_id": "JavaScript/43", "prompt": "/*\n pairsSumToZero takes a list of integers as an input.\n it returns true if there are two distinct elements in the list that\n sum to zero, and false otherwise.\n >>> pairsSumToZero([1, 3, 5, 0])\n false\n >>> pairsSumToZero([1, 3, -2, 1])\n false\n >>> pairsSumToZero([1, 2, 3, 7])\n false\n >>> pairsSumToZero([2, 4, -5, 3, 5, 7])\n true\n >>> pairsSumToZero([1])\n false\n */\nconst pairsSumToZero = (l) => {\n", "canonical_solution": " for (let i = 0; i < l.length; i++)\n for (let j = i + 1; j < l.length; j++)\n if (l[i] + l[j] == 0)\n return true;\n return false;\n}\n\n", "test": "const testPairsSumToZero = () => {\n console.assert(pairsSumToZero([1, 3, 5, 0]) === false)\n console.assert(pairsSumToZero([1, 3, -2, 1]) === false)\n console.assert(pairsSumToZero([1, 2, 3, 7]) === false)\n console.assert(pairsSumToZero([2, 4, -5, 3, 5, 7]) === true)\n console.assert(pairsSumToZero([1]) === false)\n console.assert(pairsSumToZero([-3, 9, -1, 3, 2, 30]) === true)\n console.assert(pairsSumToZero([-3, 9, -1, 3, 2, 31]) === true)\n console.assert(pairsSumToZero([-3, 9, -1, 4, 2, 30]) === false)\n console.assert(pairsSumToZero([-3, 9, -1, 4, 2, 31]) === false)\n}\n\ntestPairsSumToZero()\n", "declaration": "\nconst pairsSumToZero = (l) => {\n", "example_test": "const testPairsSumToZero = () => {\n console.assert(pairsSumToZero([1, 3, 5, 0]) === false)\n console.assert(pairsSumToZero([1, 3, -2, 1]) === false)\n console.assert(pairsSumToZero([1, 2, 3, 7]) === false)\n console.assert(pairsSumToZero([2, 4, -5, 3, 5, 7]) === true)\n}\ntestPairsSumToZero()\n", "buggy_solution": " for (let i = 0; i < l.length; i++)\n for (let j = i; j < l.length; j++)\n if (l[i] + l[j] == 0)\n return true;\n return false;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "PairsSumToZero"} @@ -56,8 +56,8 @@ {"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/58", "prompt": "/*Return sorted unique common elements for two lists.\n >>> common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121])\n [1, 5, 653]\n >>> common([5, 3, 2, 8], [3, 2])\n [2, 3]\n\n */\nconst common = (l1, l2) => {\n", "canonical_solution": " var ret = new Set();\n for (const e1 of l1)\n for (const e2 of l2)\n if (e1 == e2)\n ret.add(e1);\n return [...ret].sort();\n}\n\n", "test": "const testCommon = () => {\n console.assert(\n JSON.stringify(common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]))\n === JSON.stringify([1, 5, 653])\n )\n console.assert(\n JSON.stringify(common([5, 3, 2, 8], [3, 2]))\n === JSON.stringify([2, 3])\n )\n console.assert(\n JSON.stringify(common([4, 3, 2, 8], [3, 2, 4])) ===\n JSON.stringify([2, 3, 4])\n )\n console.assert(\n JSON.stringify(common([4, 3, 2, 8], [])) === JSON.stringify([])\n )\n}\n\ntestCommon()\n", "declaration": "\nconst common = (l1, l2) => {\n", "example_test": "const testCommon = () => {\n console.assert(\n JSON.stringify(common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]))\n === JSON.stringify([1, 5, 653])\n )\n console.assert(\n JSON.stringify(common([5, 3, 2, 8], [3, 2]))\n === JSON.stringify([2, 3])\n )\n}\ntestCommon()\n", "buggy_solution": " var ret = new Set();\n for (const e1 of l1)\n for (const e2 of l2)\n ret.add(e1);\n return [...ret].sort();\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "Common"} +{"task_id": "JavaScript/59", "prompt": "/*Return the largest prime factor of n. Assume n > 1 and is not a prime.\n >>> largestPrimeFactor(13195)\n 29\n >>> largestPrimeFactor(2048)\n 2\n */\nconst largestPrimeFactor = (n) => {\n", "canonical_solution": " var isPrime = function (k) {\n if (k < 2)\n return false;\n for (let i = 2; i < k - 1; i++)\n if (k % i == 0)\n return false;\n return true;\n }\n\n var largest = 1;\n for (let j = 2; j < n + 1; j++)\n if (n % j == 0 && isPrime(j))\n largest = Math.max(largest, j);\n return largest;\n}\n\n", "test": "const testLargestPrimeFactor = () => {\n console.assert(largestPrimeFactor(15) === 5)\n console.assert(largestPrimeFactor(27) === 3)\n console.assert(largestPrimeFactor(63) === 7)\n console.assert(largestPrimeFactor(330) === 11)\n console.assert(largestPrimeFactor(13195) === 29)\n}\n\ntestLargestPrimeFactor()\n", "declaration": "\nconst largestPrimeFactor = (n) => {\n", "example_test": "const testLargestPrimeFactor = () => {\n console.assert(largestPrimeFactor(2048) === 2)\n console.assert(largestPrimeFactor(13195) === 29)\n}\ntestLargestPrimeFactor()\n", "buggy_solution": " var isPrime = function (k) {\n if (k < 2)\n return false;\n for (let i = 2; i < k - 1; i++)\n if (k % i == 0)\n return false;\n return true;\n }\n\n var largest = 1;\n for (let j = 2; j < n + 1; j++)\n if (n % j == 0 && isPrime(n))\n largest = Math.max(largest, j);\n return largest;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "LargestPrimeFactor"} {"task_id": "JavaScript/60", "prompt": "/*sumToN is a function that sums numbers from 1 to n.\n >>> sumToN(30)\n 465\n >>> sumToN(100)\n 5050\n >>> sumToN(5)\n 15\n >>> sumToN(10)\n 55\n >>> sumToN(1)\n 1\n */\nconst sumToN = (n) => {\n", "canonical_solution": " return n * (n + 1) / 2;\n}\n\n", "test": "const testSumToN = () => {\n console.assert(sumToN(1) === 1)\n console.assert(sumToN(6) === 21)\n console.assert(sumToN(11) === 66)\n console.assert(sumToN(30) === 465)\n console.assert(sumToN(100) === 5050)\n}\n\ntestSumToN()\n", "declaration": "\nconst sumToN = (n) => {\n", "example_test": "const testSumToN = () => {\n console.assert(sumToN(1) === 1)\n console.assert(sumToN(5) === 15)\n console.assert(sumToN(10) === 55)\n console.assert(sumToN(30) === 465)\n console.assert(sumToN(100) === 5050)\n}\ntestSumToN()\n", "buggy_solution": " return n * n / 2;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "SumToN"} {"task_id": "JavaScript/61", "prompt": "/* brackets is a string of \"(\" and \")\".\n return true if every opening bracket has a corresponding closing bracket.\n\n >>> correctBracketing(\"(\")\n false\n >>> correctBracketing(\"()\")\n true\n >>> correctBracketing(\"(()())\")\n true\n >>> correctBracketing(\")(()\")\n false\n */\nconst correctBracketing = (brackets) => {\n", "canonical_solution": " var depth = 0;\n for (const b of brackets) {\n if (b == \"(\")\n depth += 1;\n else\n depth -= 1;\n if (depth < 0)\n return false;\n }\n return depth == 0;\n}\n\n", "test": "const testCorrectBracketing = () => {\n console.assert(correctBracketing('()') === true)\n console.assert(correctBracketing('(()())') === true)\n console.assert(correctBracketing('()()(()())()') === true)\n console.assert(correctBracketing('()()((()()())())(()()(()))') === true)\n console.assert(correctBracketing('((()())))') === false)\n console.assert(correctBracketing(')(()') === false)\n console.assert(correctBracketing('(') === false)\n console.assert(correctBracketing('((((') === false)\n console.assert(correctBracketing(')') === false)\n console.assert(correctBracketing('(()') === false)\n console.assert(correctBracketing('()()(()())())(()') === false)\n console.assert(correctBracketing('()()(()())()))()') === false)\n}\n\ntestCorrectBracketing()\n", "declaration": "\nconst correctBracketing = (brackets) => {\n", "example_test": "const testCorrectBracketing = () => {\n console.assert(correctBracketing('()') === true)\n console.assert(correctBracketing('(()())') === true)\n console.assert(correctBracketing(')(()') === false)\n console.assert(correctBracketing('(') === false)\n}\ntestCorrectBracketing()\n", "buggy_solution": " var depth = 0;\n for (const b of brackets) {\n if (b == \"(\")\n depth += 1;\n else\n depth -= 1;\n if (depth < 0)\n return true;\n }\n return depth == 0;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "CorrectBracketing"} {"task_id": "JavaScript/62", "prompt": "/* xs represent coefficients of a polynomial.\n xs[0] + xs[1] * x + xs[2] * x^2 + ....\n Return derivative of this polynomial in the same form.\n >>> derivative([3, 1, 2, 4, 5])\n [1, 4, 12, 20]\n >>> derivative([1, 2, 3])\n [2, 6]\n */\nconst derivative = (xs) => {\n", "canonical_solution": " return xs.map((x, i) => x * i).slice(1);\n}\n\n", "test": "const testDerivative = () => {\n console.assert(\n JSON.stringify(derivative([3, 1, 2, 4, 5])) ===\n JSON.stringify([1, 4, 12, 20])\n )\n console.assert(\n JSON.stringify(derivative([1, 2, 3])) === JSON.stringify([2, 6])\n )\n console.assert(\n JSON.stringify(derivative([3, 2, 1])) === JSON.stringify([2, 2])\n )\n console.assert(\n JSON.stringify(derivative([3, 2, 1, 0, 4])) ===\n JSON.stringify([2, 2, 0, 16])\n )\n console.assert(JSON.stringify(derivative([1])) === JSON.stringify([]))\n}\n\ntestDerivative()\n", "declaration": "\nconst derivative = (xs) => {\n", "example_test": "const testDerivative = () => {\n console.assert(\n JSON.stringify(derivative([3, 1, 2, 4, 5])) ===\n JSON.stringify([1, 4, 12, 20])\n )\n console.assert(\n JSON.stringify(derivative([1, 2, 3])) === JSON.stringify([2, 6])\n )\n}\ntestDerivative()\n", "buggy_solution": " return xs.map((x, i) => x * i);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Derivative"} @@ -90,7 +90,7 @@ {"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/92", "prompt": "/* Create a function that takes 3 numbers.\n Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.\n Returns false in any other cases.\n Examples\n anyInt(5, 2, 7) \u279e true\n anyInt(3, 2, 2) \u279e false\n anyInt(3, -2, 1) \u279e true\n anyInt(3.6, -2.2, 2) \u279e false\n */\nconst anyInt = (x, y, z) => {\n", "canonical_solution": " if (x % 1 === 0 && y % 1 === 0 && z % 1 === 0 && (x + y === z || x + z === y || x === y + z)) {\n return true\n }\n return false\n}\n\n", "test": "const testAnyInt = () => {\n console.assert(anyInt(2, 3, 1) === true)\n console.assert(anyInt(2.5, 2, 3) === false)\n console.assert(anyInt(1.5, 5, 3.5) === false)\n console.assert(anyInt(2, 6, 2) === false)\n console.assert(anyInt(4, 2, 2) === true)\n console.assert(anyInt(2.2, 2.2, 2.2) === false)\n console.assert(anyInt(-4, 6, 2) === true)\n console.assert(anyInt(2, 1, 1) === true)\n console.assert(anyInt(3, 4, 7) === true)\n console.assert(anyInt(3.0, 4, 7) === true)\n}\n\ntestAnyInt()\n", "declaration": "\nconst anyInt = (x, y, z) => {\n", "example_test": "const testAnyInt = () => {\n console.assert(anyInt(5, 2, 7) === true)\n console.assert(anyInt(3, 2, 2) === false)\n console.assert(anyInt(3, -2, 1) === true)\n console.assert(anyInt(3.6, -2.2, 2) === false)\n}\ntestAnyInt()\n", "buggy_solution": " if (x % 1 === 0 && y % 1 === 0 && z % 1 === 0 && (x + y === z || x === y + z)) {\n return true\n }\n return false\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "AnyInt"} {"task_id": "JavaScript/93", "prompt": "/*\n Write a function that takes a message, and encodes in such a \n way that it swaps case of all letters, replaces all vowels in \n the message with the letter that appears 2 places ahead of that \n vowel in the english alphabet. \n Assume only letters. \n \n Examples:\n >>> encode('test')\n 'TGST'\n >>> encode('This is a message')\n 'tHKS KS C MGSSCGG'\n */\nconst encode = (message) => {\n", "canonical_solution": " let t = ''\n for (let i = 0; i < message.length; i++) {\n let p = message[i].charCodeAt()\n if (p > 96) { p -= 32 }\n else if (p!=32 && p < 96) { p += 32 }\n if (p == 65 || p == 97 || p == 69 || p == 101 || p == 73 || p == 105 || p == 79 || p == 111 || p == 85 || p == 117) { p += 2 }\n t += String.fromCharCode(p)\n }\n return t\n}\n\n", "test": "const testEncode = () => {\n console.assert(encode('TEST') === 'tgst')\n console.assert(encode('Mudasir') === 'mWDCSKR')\n console.assert(encode('YES') === 'ygs')\n console.assert(encode('This is a message') === 'tHKS KS C MGSSCGG')\n console.assert(\n encode('I DoNt KnOw WhAt tO WrItE') === 'k dQnT kNqW wHcT Tq wRkTg'\n )\n}\n\ntestEncode()\n", "declaration": "\nconst encode = (message) => {\n", "example_test": "const testEncode = () => {\n console.assert(encode('test') === 'TGST')\n console.assert(encode('This is a message') === 'tHKS KS C MGSSCGG')\n}\ntestEncode()\n", "buggy_solution": " let t = ''\n for (let i = 0; i < message.length; i++) {\n let p = message[i].charCodeAt()\n if (p > 96) { p -= 32 }\n else if (p!=32 && p < 96) { p += 32 }\n if (p == 65 || p == 97 || p == 69 || p == 101 || p == 73 || p == 105 || p == 79 || p == 111 || p == 85 || p == 117) { p += 2 }\n }\n return t\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "Encode"} {"task_id": "JavaScript/94", "prompt": "/*You are given a list of integers.\n You need to find the largest prime value and return the sum of its digits.\n\n Examples:\n For lst = [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3] the output should be 10\n For lst = [1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1] the output should be 25\n For lst = [1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3] the output should be 13\n For lst = [0,724,32,71,99,32,6,0,5,91,83,0,5,6] the output should be 11\n For lst = [0,81,12,3,1,21] the output should be 3\n For lst = [0,8,1,2,1,7] the output should be 7\n */\nconst skjkasdkd = (lst) => {\n", "canonical_solution": " let t = 0\n for (let i = 0; i < lst.length; i++) {\n let p = 1\n for (let j = 2; j * j <= lst[i]; j++) {\n if (lst[i] % j == 0) { p = 0; break }\n }\n if (p == 1 && lst[i] > t) { t = lst[i] }\n }\n let k = 0\n while (t != 0) {\n k += t % 10\n t = (t - t % 10) / 10\n }\n return k\n}\n\n", "test": "const testSkjkasdkd = () => {\n console.assert(\n skjkasdkd([\n 0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3,\n ]) === 10\n )\n\n console.assert(\n skjkasdkd([1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) === 25\n )\n\n console.assert(\n skjkasdkd([\n 1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3,\n ]) === 13\n )\n\n console.assert(\n skjkasdkd([0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) === 11\n )\n\n console.assert(skjkasdkd([0, 81, 12, 3, 1, 21]) === 3)\n\n console.assert(skjkasdkd([0, 8, 1, 2, 1, 7]) === 7)\n\n console.assert(skjkasdkd([8191]) === 19)\n console.assert(skjkasdkd([8191, 123456, 127, 7]) === 19)\n console.assert(skjkasdkd([127, 97, 8192]) === 10)\n}\n\ntestSkjkasdkd()\n", "declaration": "\nconst skjkasdkd = (lst) => {\n", "example_test": "const testSkjkasdkd = () => {\n console.assert(\n skjkasdkd([\n 0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3,\n ]) === 10\n )\n console.assert(\n skjkasdkd([1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) === 25\n )\n console.assert(\n skjkasdkd([\n 1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3,\n ]) === 13\n )\n console.assert(\n skjkasdkd([0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) === 11\n )\n console.assert(skjkasdkd([0, 81, 12, 3, 1, 21]) === 3)\n console.assert(skjkasdkd([0, 8, 1, 2, 1, 7]) === 7)\n}\ntestSkjkasdkd()\n", "buggy_solution": " let t = 0\n for (let i = 0; i < lst.length; i++) {\n let p = 1\n for (let j = 2; j * j <= lst[i]; j++) {\n if (lst[i] % j == 0) { p = 0; break }\n }\n if (p == 1 || lst[i] > t) { t = lst[i] }\n }\n let k = 0\n while (t != 0) {\n k += t % 10\n t = (t - t % 10) / 10\n }\n return k\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "Skjkasdkd"} {"task_id": "JavaScript/95", "prompt": "/*\n Given a dictionary, return true if all keys are strings in lower \n case or all keys are strings in upper case, else return false.\n The function should return false is the given dictionary is empty.\n Examples:\n checkDictCase({\"a\":\"apple\", \"b\":\"banana\"}) should return true.\n checkDictCase({\"a\":\"apple\", \"A\":\"banana\", \"B\":\"banana\"}) should return false.\n checkDictCase({\"a\":\"apple\", 8:\"banana\", \"a\":\"apple\"}) should return false.\n checkDictCase({\"Name\":\"John\", \"Age\":\"36\", \"City\":\"Houston\"}) should return false.\n checkDictCase({\"STATE\":\"NC\", \"ZIP\":\"12345\" }) should return true.\n */\nconst checkDictCase = (dict) => {\n", "canonical_solution": " let c = 0\n let lo = 1\n let hi = 1\n for (let key in dict) {\n c++\n for (let i = 0; i < key.length; i++) {\n if (key[i].charCodeAt() < 65 || key[i].charCodeAt() > 90) { hi = 0 }\n if (key[i].charCodeAt() < 97 || key[i].charCodeAt() > 122) { lo = 0 }\n }\n }\n if ((lo == 0 && hi == 0) || c == 0) { return false }\n return true\n}\n\n", "test": "const testCheckDictCase = () => {\n console.assert(checkDictCase({ p: 'pineapple', b: 'banana' }) === true)\n console.assert(\n checkDictCase({ p: 'pineapple', A: 'banana', B: 'banana' }) === false\n )\n console.assert(\n checkDictCase({ p: 'pineapple', 5: 'banana', a: 'apple' }) === false\n )\n console.assert(\n checkDictCase({ Name: 'John', Age: '36', City: 'Houston' }) === false\n )\n console.assert(checkDictCase({ STATE: 'NC', ZIP: '12345' }) === true)\n console.assert(checkDictCase({ fruit: 'Orange', taste: 'Sweet' }) === true)\n console.assert(checkDictCase({}) === false)\n}\n\ntestCheckDictCase()\n", "declaration": "\nconst checkDictCase = (dict) => {\n", "example_test": "const testCheckDictCase = () => {\n console.assert(checkDictCase({ p: 'pineapple', b: 'banana' }) === true)\n console.assert(\n checkDictCase({ p: 'pineapple', A: 'banana', B: 'banana' }) === false\n )\n console.assert(\n checkDictCase({ p: 'pineapple', 8: 'banana', a: 'apple' }) === false\n )\n console.assert(\n checkDictCase({ Name: 'John', Age: '36', City: 'Houston' }) === false\n )\n console.assert(checkDictCase({ STATE: 'NC', ZIP: '12345' }) === true)\n}\ntestCheckDictCase()\n", "buggy_solution": " let c = 0\n let lo = 1\n let hi = 1\n for (let key in dict) {\n c++\n for (let i = 0; i < key.length; i++) {\n if (key[i].charCodeAt() < 65 || key[i].charCodeAt() > 90) { hi = 0 }\n if (key[i].charCodeAt() < 97 || key[i].charCodeAt() > 122) { lo = 0 }\n }\n }\n if ((lo == 0 && hi == 0) && c == 0) { return false }\n return true\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "CheckDictCase"} @@ -99,7 +99,7 @@ {"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/101", "prompt": "/*\n You will be given a string of words separated by commas or spaces. Your task is\n to split the string into words and return an array of the words.\n \n For example:\n wordsString(\"Hi, my name is John\") == [\"Hi\", \"my\", \"name\", \"is\", \"John\"]\n wordsString(\"One, two, three, four, five, six\") == [\"One\", \"two\", \"three\", \"four\", \"five\", \"six\"]\n */\nconst wordsString = (s) => {\n", "canonical_solution": " let t = ''\n let p = []\n let k = 0\n for (let i = 0; i < s.length; i++) {\n if (s[i] == ' ' || s[i] == ',') {\n if (k == 0) {\n k = 1;\n p.push(t);\n t = '';\n }\n }\n else {\n k = 0;\n t += s[i]\n }\n }\n if (t != '') {\n p.push(t);\n }\n return p\n}\n\n", "test": "const testWordsString = () => {\n console.assert(\n JSON.stringify(wordsString('Hi, my name is John')) ===\n JSON.stringify(['Hi', 'my', 'name', 'is', 'John'])\n )\n console.assert(\n JSON.stringify(wordsString('One, two, three, four, five, six')) ===\n JSON.stringify(['One', 'two', 'three', 'four', 'five', 'six'])\n )\n console.assert(\n JSON.stringify(wordsString('Hi, my name')) ===\n JSON.stringify(['Hi', 'my', 'name'])\n )\n console.assert(\n JSON.stringify(wordsString('One,, two, three, four, five, six,')) ===\n JSON.stringify(['One', 'two', 'three', 'four', 'five', 'six'])\n )\n console.assert(JSON.stringify(wordsString('')) === JSON.stringify([]))\n console.assert(\n JSON.stringify(wordsString('ahmed , gamal')) ===\n JSON.stringify(['ahmed', 'gamal'])\n )\n}\n\ntestWordsString()\n", "declaration": "\nconst wordsString = (s) => {\n", "example_test": "const testWordsString = () => {\n console.assert(\n JSON.stringify(wordsString('Hi, my name is John')) ===\n JSON.stringify(['Hi', 'my', 'name', 'is', 'John'])\n )\n console.assert(\n JSON.stringify(wordsString('One, two, three, four, five, six')) ===\n JSON.stringify(['One', 'two', 'three', 'four', 'five', 'six'])\n )\n}\ntestWordsString()\n", "buggy_solution": " let t = ','\n let p = []\n let k = 0\n for (let i = 0; i < s.length; i++) {\n if (s[i] == ' ' || s[i] == ',') {\n if (k == 0) {\n k = 1;\n p.push(t);\n t = ',';\n }\n }\n else {\n k = 0;\n t += s[i]\n }\n }\n if (t != '') {\n p.push(t);\n }\n return p\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "WordsString"} {"task_id": "JavaScript/102", "prompt": "/*This function takes two positive numbers x and y and returns the\n biggest even integer number that is in the range [x, y] inclusive. If \n there's no such number, then the function should return -1.\n\n For example:\n chooseNum(12, 15) = 14\n chooseNum(13, 12) = -1\n */\nconst chooseNum = (x, y) => {\n", "canonical_solution": " for (let i = y; i >= x; i--) {\n if (i % 2 == 0) {return i }\n }\n return -1\n}\n\n", "test": "const testChooseNum = () => {\n console.assert(chooseNum(12, 15) === 14)\n console.assert(chooseNum(13, 12) === -1)\n console.assert(chooseNum(33, 12354) === 12354)\n console.assert(chooseNum(5234, 5233) === -1)\n console.assert(chooseNum(6, 29) === 28)\n console.assert(chooseNum(27, 10) === -1)\n console.assert(chooseNum(7, 7) === -1)\n console.assert(chooseNum(546, 546) === 546)\n}\n\ntestChooseNum()\n", "declaration": "\nconst chooseNum = (x, y) => {\n", "example_test": "const testChooseNum = () => {\n console.assert(chooseNum(12, 15) === 14)\n console.assert(chooseNum(13, 12) === -1)\n}\ntestChooseNum()\n", "buggy_solution": " for (let i = y; i >= x; i--) {\n if (i % 2 == 0) {return i }\n }\n return x\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "ChooseNum"} {"task_id": "JavaScript/103", "prompt": "/*You are given two positive integers n and m, and your task is to compute the\n average of the integers from n through m (including n and m). \n Round the answer to the nearest integer and convert that to binary.\n If n is greater than m, return -1.\n Example:\n roundedAvg(1, 5) => \"0b11\"\n roundedAvg(7, 5) => -1\n roundedAvg(10, 20) => \"0b1111\"\n roundedAvg(20, 33) => \"0b11010\"\n */\nconst roundedAvg = (n, m) => {\n", "canonical_solution": " if (n > m) { return -1 }\n let k = (n + m) / 2\n if (k % 1 != 0) { k = (n + m + 1) / 2 }\n return '0b' + k.toString(2)\n}\n\n", "test": "const testRoundedAvg = () => {\n console.assert(roundedAvg(1, 5) === '0b11')\n console.assert(roundedAvg(7, 13) === '0b1010')\n console.assert(roundedAvg(964, 977) === '0b1111001011')\n console.assert(roundedAvg(996, 997) === '0b1111100101')\n console.assert(roundedAvg(560, 851) === '0b1011000010')\n console.assert(roundedAvg(185, 546) === '0b101101110')\n console.assert(roundedAvg(362, 496) === '0b110101101')\n console.assert(roundedAvg(350, 902) === '0b1001110010')\n console.assert(roundedAvg(197, 233) === '0b11010111')\n console.assert(roundedAvg(7, 5) === -1)\n console.assert(roundedAvg(5, 1) === -1)\n console.assert(roundedAvg(5, 5) === '0b101')\n}\n\ntestRoundedAvg()\n", "declaration": "\nconst roundedAvg = (n, m) => {\n", "example_test": "const testRoundedAvg = () => {\n console.assert(roundedAvg(1, 5) === '0b11')\n console.assert(roundedAvg(7, 13) === '0b1010')\n console.assert(roundedAvg(7, 5) === -1)\n console.assert(roundedAvg(10,20) === \"0b1111\")\n console.assert(roundedAvg(20,33) === '0b11011')\n}\ntestRoundedAvg()\n", "buggy_solution": " if (n > m) { return -1 }\n let k = (n + m) / 2\n if (k % 1 != 0) { k = (n + m) / 2 }\n return '0b' + k.toString(2)\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "RoundedAvg"} {"task_id": "JavaScript/104", "prompt": "/*Given a list of positive integers x. return a sorted list of all \n elements that hasn't any even digit.\n\n Note: Returned list should be sorted in increasing order.\n \n For example:\n >>> uniqueDigits([15, 33, 1422, 1])\n [1, 15, 33]\n >>> uniqueDigits([152, 323, 1422, 10])\n []\n */\nconst uniqueDigits = (x) => {\n", "canonical_solution": " let p = []\n for (let i = 0; i < x.length; i++) {\n let h = x[i]\n let boo = 1\n while (h > 0) {\n let r = h % 10\n if (r % 2 == 0) {\n boo = 0;\n break;\n }\n h = (h - r) / 10\n }\n if (boo) {\n p.push(x[i])\n }\n }\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "test": "const testUniqueDigits = () => {\n console.assert(\n JSON.stringify(uniqueDigits([15, 33, 1422, 1])) ===\n JSON.stringify([1, 15, 33])\n )\n console.assert(\n JSON.stringify(uniqueDigits([152, 323, 1422, 10])) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(uniqueDigits([12345, 2033, 111, 151])) ===\n JSON.stringify([111, 151])\n )\n console.assert(\n JSON.stringify(uniqueDigits([135, 103, 31])) === JSON.stringify([31, 135])\n )\n}\n\ntestUniqueDigits()\n", "declaration": "\nconst uniqueDigits = (x) => {\n", "example_test": "const testUniqueDigits = () => {\n console.assert(\n JSON.stringify(uniqueDigits([15, 33, 1422, 1])) ===\n JSON.stringify([1, 15, 33])\n )\n console.assert(\n JSON.stringify(uniqueDigits([152, 323, 1422, 10])) === JSON.stringify([])\n )\n}\ntestUniqueDigits()\n", "buggy_solution": " let p = []\n for (let i = 0; i < x.length; i++) {\n let h = x[i]\n let boo = 1\n while (h > 0) {\n let r = h % 10\n if (r % 2 == 0) {\n boo = 0;\n break;\n }\n h = (h - r) / 10\n }\n if (boo) {\n p.push(x[i]);\n p.push(h);\n }\n }\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "UniqueDigits"} @@ -112,7 +112,7 @@ {"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/114", "prompt": "/*\n Given an array of integers nums, find the minimum sum of any non-empty sub-array\n of nums.\n Example\n minSubArraySum([2, 3, 4, 1, 2, 4]) == 1\n minSubArraySum([-1, -2, -3]) == -6\n */\nconst minSubArraySum = (nums) => {\n", "canonical_solution": " let min = nums[0]\n for (let i = 0; i < nums.length; i++) {\n for (let j = i + 1; j <= nums.length; j++) {\n let s = 0;\n for (let k = i; k < j; k++) {\n s += nums[k]\n }\n if (s < min) { min = s }\n }\n }\n return min\n}\n\n", "test": "const testMinSubArraySum = () => {\n console.assert(minSubArraySum([2, 3, 4, 1, 2, 4]) === 1)\n console.assert(minSubArraySum([-1, -2, -3]) === -6)\n console.assert(minSubArraySum([-1, -2, -3, 2, -10]) === -14)\n console.assert(minSubArraySum([-9999999999999999]) === -9999999999999999)\n console.assert(minSubArraySum([0, 10, 20, 1000000]) === 0)\n console.assert(minSubArraySum([-1, -2, -3, 10, -5]) === -6)\n console.assert(minSubArraySum([100, -1, -2, -3, 10, -5]) === -6)\n console.assert(minSubArraySum([10, 11, 13, 8, 3, 4]) === 3)\n console.assert(minSubArraySum([100, -33, 32, -1, 0, -2]) === -33)\n console.assert(minSubArraySum([-10]) === -10)\n console.assert(minSubArraySum([7]) === 7)\n console.assert(minSubArraySum([1, -1]) === -1)\n}\n\ntestMinSubArraySum()\n", "declaration": "\nconst minSubArraySum = (nums) => {\n", "example_test": "const testMinSubArraySum = () => {\n console.assert(minSubArraySum([2, 3, 4, 1, 2, 4]) === 1)\n console.assert(minSubArraySum([-1, -2, -3]) === -6)\n}\ntestMinSubArraySum()\n", "buggy_solution": " let min = Math.min(nums)\n for (let i = 0; i < nums.length; i++) {\n for (let j = i + 1; j <= nums.length; j++) {\n let s = 0;\n for (let k = i; k < j; k++) {\n s += nums[k]\n }\n if (s < min) { min = s }\n }\n }\n return min\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "Minsubarraysum"} {"task_id": "JavaScript/115", "prompt": "/*\n You are given a rectangular grid of wells. Each row represents a single well,\n and each 1 in a row represents a single unit of water.\n Each well has a corresponding bucket that can be used to extract water from it, \n and all buckets have the same capacity.\n Your task is to use the buckets to empty the wells.\n Output the number of times you need to lower the buckets.\n\n Example 1:\n Input: \n grid : [[0,0,1,0], [0,1,0,0], [1,1,1,1]]\n bucket_capacity : 1\n Output: 6\n\n Example 2:\n Input: \n grid : [[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]]\n bucket_capacity : 2\n Output: 5\n \n Example 3:\n Input: \n grid : [[0,0,0], [0,0,0]]\n bucket_capacity : 5\n Output: 0\n\n Constraints:\n * all wells have the same length\n * 1 <= grid.length <= 10^2\n * 1 <= grid[:,1].length <= 10^2\n * grid[i][j] -> 0 | 1\n * 1 <= capacity <= 10\n */\nconst maxFill = (grid, capacity) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < grid.length; i++) {\n let m = 0\n for (let j = 0; j < grid[i].length; j++) {\n if (grid[i][j] == 1) { m++ }\n }\n while (m > 0) {\n m -= capacity;\n p++;\n }\n }\n return p\n}\n\n", "test": "const testMaxFill = () => {\n console.assert(\n maxFill(\n [\n [0, 0, 1, 0],\n [0, 1, 0, 0],\n [1, 1, 1, 1],\n ],\n 1\n ) === 6\n )\n console.assert(\n maxFill(\n [\n [0, 0, 1, 1],\n [0, 0, 0, 0],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n ],\n 2\n ) === 5\n )\n console.assert(\n maxFill(\n [\n [0, 0, 0],\n [0, 0, 0],\n ],\n 5\n ) === 0\n )\n console.assert(\n maxFill(\n [\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n ],\n 2\n ) === 4\n )\n console.assert(\n maxFill(\n [\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n ],\n 9\n ) === 2\n )\n}\n\ntestMaxFill()\n", "declaration": "\nconst maxFill = (grid, capacity) => {\n", "example_test": "const testMaxFill = () => {\n console.assert(\n maxFill(\n [\n [0, 0, 1, 0],\n [0, 1, 0, 0],\n [1, 1, 1, 1],\n ],\n 1\n ) === 6\n )\n console.assert(\n maxFill(\n [\n [0, 0, 1, 1],\n [0, 0, 0, 0],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n ],\n 2\n ) === 5\n )\n console.assert(\n maxFill(\n [\n [0, 0, 0],\n [0, 0, 0],\n ],\n 5\n ) === 0\n )\n}\ntestMaxFill()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < grid.length; i++) {\n let m = 0\n for (let j = 1; j < grid[i].length; j++) {\n if (grid[i][j] == 1) { m++ }\n }\n while (m > 0) {\n m -= capacity;\n p++;\n }\n }\n return p\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "MaxFill"} {"task_id": "JavaScript/116", "prompt": "/*\n In this Kata, you have to sort an array of non-negative integers according to\n number of ones in their binary representation in ascending order.\n For similar number of ones, sort based on decimal value.\n\n It must be implemented like this:\n >>> sortArray([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]\n >>> sortArray([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]\n >>> sortArray([1, 0, 2, 3, 4]) [0, 1, 2, 3, 4]\n */\nconst sortArray = (arr) => {\n", "canonical_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n let w1 = p[ind].toString(2)\n let f1 = 0\n for (let u = 0; u < w1.length; u++) {\n if (w1[u] == '1') { f1++ }\n }\n let w2 = p[k].toString(2)\n let f2 = 0\n for (let u = 0; u < w2.length; u++) {\n if (w2[u] == '1') { f2++ }\n }\n if (f2 < f1 || (f1 == f2 && p[k] < p[ind])) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "test": "const testSortArray = () => {\n console.assert(\n JSON.stringify(sortArray([1, 5, 2, 3, 4])) ===\n JSON.stringify([1, 2, 4, 3, 5])\n )\n\n console.assert(\n JSON.stringify(sortArray([-2, -3, -4, -5, -6])) ===\n JSON.stringify([-4, -2, -6, -5, -3])\n )\n console.assert(\n JSON.stringify(sortArray([1, 0, 2, 3, 4])) ===\n JSON.stringify([0, 1, 2, 4, 3])\n )\n console.assert(JSON.stringify(sortArray([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(sortArray([2, 5, 77, 4, 5, 3, 5, 7, 2, 3, 4])) ===\n JSON.stringify([2, 2, 4, 4, 3, 3, 5, 5, 5, 7, 77])\n )\n console.assert(\n JSON.stringify(sortArray([3, 6, 44, 12, 32, 5])) ===\n JSON.stringify([32, 3, 5, 6, 12, 44])\n )\n console.assert(\n JSON.stringify(sortArray([2, 4, 8, 16, 32])) ===\n JSON.stringify([2, 4, 8, 16, 32])\n )\n console.assert(\n JSON.stringify(sortArray([2, 4, 8, 16, 32])) ===\n JSON.stringify([2, 4, 8, 16, 32])\n )\n}\n\ntestSortArray()\n", "declaration": "\nconst sortArray = (arr) => {\n", "example_test": "const testSortArray = () => {\n console.assert(\n JSON.stringify(sortArray([1, 5, 2, 3, 4])) ===\n JSON.stringify([1, 2, 4, 3, 5])\n )\n console.assert(\n JSON.stringify(sortArray([-2, -3, -4, -5, -6])) ===\n JSON.stringify([-4, -2, -6, -5, -3])\n )\n console.assert(\n JSON.stringify(sortArray([1, 0, 2, 3, 4])) ===\n JSON.stringify([0, 1, 2, 4, 3])\n )\n}\ntestSortArray()\n", "buggy_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n let w1 = p[ind].toString(2)\n let f1 = 0\n for (let u = 0; u < w1.length; u++) {\n if (w1[u] == '1') { f1++ }\n }\n let w2 = p[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"} @@ -127,12 +127,12 @@ {"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/129", "prompt": "/*\n Given a grid with N rows and N columns (N >= 2) and a positive integer k, \n each cell of the grid contains a value. Every integer in the range [1, N * N]\n inclusive appears exactly once on the cells of the grid.\n\n You have to find the minimum path of length k in the grid. You can start\n from any cell, and in each step you can move to any of the neighbor cells,\n in other words, you can go to cells which share an edge with you current\n cell.\n Please note that a path of length k means visiting exactly k cells (not\n necessarily distinct).\n You CANNOT go off the grid.\n A path A (of length k) is considered less than a path B (of length k) if\n after making the ordered lists of the values on the cells that A and B go\n through (let's call them lst_A and lst_B), lst_A is lexicographically less\n than lst_B, in other words, there exist an integer index i (1 <= i <= k)\n such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\n lst_A[j] = lst_B[j].\n It is guaranteed that the answer is unique.\n Return an ordered list of the values on the cells that the minimum path go through.\n\n Examples:\n\n Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3\n Output: [1, 2, 1]\n\n Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1\n Output: [1]\n */\nconst minPath = (grid, k) => {\n", "canonical_solution": " let m = 0\n let n = 0\n for (let i = 0; i < grid.length; i++) {\n for (let j = 0; j < grid.length; j++) {\n if (grid[i][j] == 1) {\n m = i;\n n = j;\n break;\n }\n }\n }\n let min = grid.length * grid.length\n if (m > 0 && grid[m - 1][n] < min) { min = grid[m - 1][n] }\n if (n > 0 && grid[m][n - 1] < min) { min = grid[m][n - 1] }\n if (m < grid.length - 1 && grid[m + 1][n] < min) { min = grid[m + 1][n] }\n if (n < grid.length - 1 && grid[m][n + 1] < min) { min = grid[m][n + 1] }\n let p = []\n for (let i = 0; i < k; i++) {\n if (i % 2 == 0) { p.push(1) }\n else { p.push(min) }\n }\n return p\n}\n\n", "test": "const testMinPath = () => {\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9],\n ],\n 3\n )\n ) === JSON.stringify([1, 2, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [5, 9, 3],\n [4, 1, 6],\n [7, 8, 2],\n ],\n 1\n )\n ) === JSON.stringify([1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n ],\n 4\n )\n ) === JSON.stringify([1, 2, 1, 2])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [6, 4, 13, 10],\n [5, 7, 12, 1],\n [3, 16, 11, 15],\n [8, 14, 9, 2],\n ],\n 7\n )\n ) === JSON.stringify([1, 10, 1, 10, 1, 10, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [8, 14, 9, 2],\n [6, 4, 13, 15],\n [5, 7, 1, 12],\n [3, 10, 11, 16],\n ],\n 5\n )\n ) === JSON.stringify([1, 7, 1, 7, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [11, 8, 7, 2],\n [5, 16, 14, 4],\n [9, 3, 15, 6],\n [12, 13, 10, 1],\n ],\n 9\n )\n ) === JSON.stringify([1, 6, 1, 6, 1, 6, 1, 6, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [12, 13, 10, 1],\n [9, 3, 15, 6],\n [5, 16, 14, 4],\n [11, 8, 7, 2],\n ],\n 12\n )\n ) === JSON.stringify([1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [2, 7, 4],\n [3, 1, 5],\n [6, 8, 9],\n ],\n 8\n )\n ) === JSON.stringify([1, 3, 1, 3, 1, 3, 1, 3])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [6, 1, 5],\n [3, 8, 9],\n [2, 7, 4],\n ],\n 8\n )\n ) === JSON.stringify([1, 5, 1, 5, 1, 5, 1, 5])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2],\n [3, 4],\n ],\n 10\n )\n ) === JSON.stringify([1, 2, 1, 2, 1, 2, 1, 2, 1, 2])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 3],\n [4, 2],\n ],\n 10\n )\n ) === JSON.stringify([1, 3, 1, 3, 1, 3, 1, 3, 1, 3])\n )\n}\n\ntestMinPath()\n", "declaration": "\nconst minPath = (grid, k) => {\n", "example_test": "const testMinPath = () => {\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9],\n ],\n 3\n )\n ) === JSON.stringify([1, 2, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [5, 9, 3],\n [4, 1, 6],\n [7, 8, 2],\n ],\n 1\n )\n ) === JSON.stringify([1])\n )\n}\ntestMinPath()\n", "buggy_solution": " let m = 0\n let n = 0\n for (let i = 0; i < grid.length; i++) {\n for (let j = 0; j < grid.length; j++) {\n if (grid[i][j] == 1) {\n m = i;\n n = j;\n break;\n }\n }\n }\n let min = grid.length * grid.length\n if (m > 0 && grid[m - 1][n] < min) { min = grid[m][n] }\n if (n > 0 && grid[m][n - 1] < min) { min = grid[m][n] }\n if (m < grid.length - 1 && grid[m + 1][n] < min) { min = grid[m][n] }\n if (n < grid.length - 1 && grid[m][n + 1] < min) { min = grid[m][n] }\n let p = []\n for (let i = 0; i < k; i++) {\n if (i % 2 == 0) { p.push(1) }\n else { p.push(min) }\n }\n return p\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Minpath"} {"task_id": "JavaScript/130", "prompt": "/*Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in \n the last couple centuries. However, what people don't know is Tribonacci sequence.\n Tribonacci sequence is defined by the recurrence:\n tri(1) = 3\n tri(n) = 1 + n / 2, if n is even.\n tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\n For example:\n tri(2) = 1 + (2 / 2) = 2\n tri(4) = 3\n tri(3) = tri(2) + tri(1) + tri(4)\n = 2 + 3 + 3 = 8 \n You are given a non-negative integer number n, you have to a return a list of the \n first n + 1 numbers of the Tribonacci sequence.\n Examples:\n tri(3) = [1, 3, 2, 8]\n */\nconst tri = (n) => {\n", "canonical_solution": " if (n == 0) { return [1] }\n if (n == 1) { return [1, 3] }\n let p = [1, 3]\n for (let i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n p.push(1 + i / 2)\n }\n else {\n p.push(p[i - 2] + p[i - 1] + 1 + (i + 1) / 2)\n }\n }\n return p\n}\n\n", "test": "const testTri = () => {\n console.assert(JSON.stringify(tri(3)) === JSON.stringify([1, 3, 2.0, 8.0]))\n\n console.assert(\n JSON.stringify(tri(4)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0])\n )\n console.assert(\n JSON.stringify(tri(5)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0])\n )\n console.assert(\n JSON.stringify(tri(6)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0])\n )\n console.assert(\n JSON.stringify(tri(7)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0])\n )\n console.assert(\n JSON.stringify(tri(8)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0])\n )\n console.assert(\n JSON.stringify(tri(9)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0])\n )\n console.assert(\n JSON.stringify(tri(20)) ===\n JSON.stringify([\n 1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0, 6.0, 48.0, 7.0, 63.0,\n 8.0, 80.0, 9.0, 99.0, 10.0, 120.0, 11.0,\n ])\n )\n console.assert(JSON.stringify(tri(0)) === JSON.stringify([1]))\n console.assert(JSON.stringify(tri(1)) === JSON.stringify([1, 3]))\n}\n\ntestTri()\n", "declaration": "\nconst tri = (n) => {\n", "example_test": "const testTri = () => {\n console.assert(JSON.stringify(tri(3)) === JSON.stringify([1, 3, 2.0, 8.0]))\n}\ntestTri()\n", "buggy_solution": " if (n == 0) { return [1] }\n if (n == 1) { return [1, 3] }\n let p = [1, 3]\n for (let i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n p.push(1 + i / 2)\n }\n else {\n p.push(p[i - 2] + p[i - 1] + 1 + i + (i + 1) / 2)\n }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Tri"} {"task_id": "JavaScript/131", "prompt": "/*Given a positive integer n, return the product of the odd digits.\n Return 0 if all digits are even.\n For example:\n digits(1) == 1\n digits(4) == 0\n digits(235) == 15\n */\nconst digits = (n) => {\n", "canonical_solution": " let p = 1\n let k = 1\n while (n > 0) {\n let y = n % 10\n if (y % 2 == 1) {\n p *= y; k = 0;\n }\n n = (n - n % 10) / 10\n }\n if (k == 0) { return p }\n return 0\n}\n\n", "test": "const testDigits = () => {\n console.assert(digits(5) === 5)\n console.assert(digits(54) === 5)\n console.assert(digits(120) === 1)\n console.assert(digits(5014) === 5)\n console.assert(digits(98765) === 315)\n console.assert(digits(5576543) === 2625)\n console.assert(digits(2468) === 0)\n}\n\ntestDigits()\n", "declaration": "\nconst digits = (n) => {\n", "example_test": "const testDigits = () => {\n console.assert(digits(1) === 1)\n console.assert(digits(4) === 0)\n console.assert(digits(235) === 15)\n}\ntestDigits()\n", "buggy_solution": " let p = 1\n let k = 1\n while (n > 0) {\n let y = n % 10\n if (y % 2 == 1) {\n p *= p*y; k = 0;\n }\n n = (n - n % 10) / 10\n }\n if (k == 0) { return p }\n return 0\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Digits"} {"task_id": "JavaScript/132", "prompt": "/*\n Create a function that takes a string as input which contains only square brackets.\n The function should return true if and only if there is a valid subsequence of brackets\n where at least one bracket in the subsequence is nested.\n isNested('[[]]') \u279e true\n isNested('[]]]]]]][[[[[]') \u279e false\n isNested('[][]') \u279e false\n isNested('[]') \u279e false\n isNested('[[][]]') \u279e true\n isNested('[[]][[') \u279e true\n */\nconst isNested = (string) => {\n", "canonical_solution": " let opening_bracket_index = []\n let closing_bracket_index1 = []\n for (let i = 0; i < string.length; i++) {\n if (string[i] == '[') {\n opening_bracket_index.push(i)\n }\n else {\n closing_bracket_index1.push(i)\n }\n }\n let closing_bracket_index = []\n for (let i = 0; i < closing_bracket_index1.length; i++) {\n closing_bracket_index.push(closing_bracket_index1[closing_bracket_index1.length - i - 1])\n }\n let cnt = 0\n let i = 0\n let l = closing_bracket_index.length\n for (let k = 0; k < opening_bracket_index.length; k++) {\n if (i < l && opening_bracket_index[k] < closing_bracket_index[i]) {\n cnt += 1;\n i += 1;\n }\n }\n return cnt >= 2\n}\n\n", "test": "const testIsNested = () => {\n console.assert(isNested('[[]]') === true)\n console.assert(isNested('[]]]]]]][[[[[]') === false)\n console.assert(isNested('[][]') === false)\n console.assert(isNested('[]') === false)\n console.assert(isNested('[[[[]]]]') === true)\n console.assert(isNested('[]]]]]]]]]]') === false)\n console.assert(isNested('[][][[]]') === true)\n console.assert(isNested('[[]') === false)\n console.assert(isNested('[]]') === false)\n console.assert(isNested('[[]][[') === true)\n console.assert(isNested('[[][]]') === true)\n console.assert(isNested('') === false)\n console.assert(isNested('[[[[[[[[') === false)\n console.assert(isNested(']]]]]]]]') === false)\n}\n\ntestIsNested()\n", "declaration": "\nconst isNested = (string) => {\n", "example_test": "const testIsNested = () => {\n console.assert(isNested('[[]]') === true)\n console.assert(isNested('[]]]]]]][[[[[]') === false)\n console.assert(isNested('[][]') === false)\n console.assert(isNested('[]') === false)\n console.assert(isNested('[[]][[') === true)\n console.assert(isNested('[[][]]') === true)\n}\ntestIsNested()\n", "buggy_solution": " let opening_bracket_index = []\n let closing_bracket_index1 = []\n for (let i = 0; i < string.length; i++) {\n if (string[i] == '(') {\n opening_bracket_index.push(i)\n }\n else {\n closing_bracket_index1.push(i)\n }\n }\n let closing_bracket_index = []\n for (let i = 0; i < closing_bracket_index1.length; i++) {\n closing_bracket_index.push(closing_bracket_index1[closing_bracket_index1.length - i - 1])\n }\n let cnt = 0\n let i = 0\n let l = closing_bracket_index.length\n for (let k = 0; k < opening_bracket_index.length; k++) {\n if (i < l && opening_bracket_index[k] < closing_bracket_index[i]) {\n cnt += 1;\n i += 1;\n }\n }\n return cnt >= 2\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "IsNested"} {"task_id": "JavaScript/133", "prompt": "/*You are given a list of numbers.\n You need to return the sum of squared numbers in the given list,\n round each element in the list to the upper int(Ceiling) first.\n Examples:\n For lst = [1,2,3] the output should be 14\n For lst = [1,4,9] the output should be 98\n For lst = [1,3,5,7] the output should be 84\n For lst = [1.4,4.2,0] the output should be 29\n For lst = [-2.4,1,1] the output should be 6\n */\nconst sumSquares = (lst) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n let y = lst[i]\n if (y % 1 != 0) {\n if (y > 0) { y = y - y % 1 + 1 }\n else { y = -y; y = y - y % 1 }\n }\n p += y * y\n }\n return p\n}\n\n", "test": "const testSumSquares = () => {\n console.assert(sumSquares([1, 2, 3]) === 14)\n console.assert(sumSquares([1.0, 2, 3]) === 14)\n console.assert(sumSquares([1, 3, 5, 7]) === 84)\n console.assert(sumSquares([1.4, 4.2, 0]) === 29)\n console.assert(sumSquares([-2.4, 1, 1]) === 6)\n\n console.assert(sumSquares([100, 1, 15, 2]) === 10230)\n console.assert(sumSquares([10000, 10000]) === 200000000)\n console.assert(sumSquares([-1.4, 4.6, 6.3]) === 75)\n console.assert(sumSquares([-1.4, 17.9, 18.9, 19.9]) === 1086)\n\n console.assert(sumSquares([0]) === 0)\n console.assert(sumSquares([-1]) === 1)\n console.assert(sumSquares([-1, 1, 0]) === 2)\n}\n\ntestSumSquares()\n", "declaration": "\nconst sumSquares = (lst) => {\n", "example_test": "const testSumSquares = () => {\n console.assert(sumSquares([1, 2, 3]) === 14)\n console.assert(sumSquares([1, 4, 9]) === 98)\n console.assert(sumSquares([1, 3, 5, 7]) === 84)\n console.assert(sumSquares([1.4, 4.2, 0]) === 29)\n console.assert(sumSquares([-2.4, 1, 1]) === 6)\n}\ntestSumSquares()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n let y = lst[i]\n if (y % 1 != 0) {\n if (y > 0) { y = y - y % 1 + 1 }\n else { y = -y; y = y - y % 1 }\n }\n p += y * 2\n }\n return p\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "SumSquares"} -{"task_id": "JavaScript/134", "prompt": "/* Create a function that returns true if the last character\n of a given string is an alphabetical character and is not\n a part of a word, and false otherwise.\n Note: \"word\" is a group of characters separated by space.\n Examples:\n checkIfLastCharIsALetter(\"apple pie\") \u279e false\n checkIfLastCharIsALetter(\"apple pi e\") \u279e true\n checkIfLastCharIsALetter(\"apple pi e \") \u279e false\n checkIfLastCharIsALetter(\"\") \u279e false\n */\nconst checkIfLastCharIsALetter = (txt) => {\n", "canonical_solution": " let len = txt.length\n if (len == 0) { return false }\n let y = txt[len - 1].charCodeAt()\n if (len == 1) {\n if ((y >= 65 && y <= 90) || (y >= 97 && y <= 122)) { return true }\n return false\n }\n if (txt[len - 2] == ' ' && ((y >= 65 && y <= 90) || (y >= 97 && y <= 122))) { return true }\n return false\n}\n\n", "test": "const testCheckIfLastCharIsALetter = () => {\n console.assert(checkIfLastCharIsALetter('apple') === false)\n console.assert(checkIfLastCharIsALetter('apple pi e') === true)\n console.assert(checkIfLastCharIsALetter('eeeee') === false)\n console.assert(checkIfLastCharIsALetter('A') === true)\n console.assert(checkIfLastCharIsALetter('Pumpkin pie ') === false)\n console.assert(checkIfLastCharIsALetter('Pumpkin pie 1') === false)\n console.assert(checkIfLastCharIsALetter('') === false)\n console.assert(checkIfLastCharIsALetter('eeeee e ') === false)\n console.assert(checkIfLastCharIsALetter('apple pie') === false)\n console.assert(checkIfLastCharIsALetter('apple pi e ') === false)\n}\n\ntestCheckIfLastCharIsALetter()\n", "declaration": "\nconst checkIfLastCharIsALetter = (txt) => {\n", "example_test": "const testCheckIfLastCharIsALetter = () => {\n console.assert(checkIfLastCharIsALetter('apple pi e') === true)\n console.assert(checkIfLastCharIsALetter('') === false)\n console.assert(checkIfLastCharIsALetter('apple pie') === false)\n console.assert(checkIfLastCharIsALetter('apple pi e ') === false)\n}\ntestCheckIfLastCharIsALetter()\n", "buggy_solution": " let len = txt.length\n if (len == 0) { return false }\n let y = txt[len - 1].charCodeAt()\n if (len == 1) {\n if ((y >= 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/134", "prompt": "/* Create a function that returns true if the last character\n of a given string is an alphabetical character and is not\n a part of a word, and false otherwise.\n Note: \"word\" is a group of characters separated by space.\n Examples:\n checkIfLastCharIsALetter(\"apple pie\") \u279e false\n checkIfLastCharIsALetter(\"apple pi e\") \u279e true\n checkIfLastCharIsALetter(\"apple pi e \") \u279e false\n checkIfLastCharIsALetter(\"\") \u279e false\n */\nconst checkIfLastCharIsALetter = (txt) => {\n", "canonical_solution": " let len = txt.length\n if (len == 0) { return false }\n let y = txt[len - 1].charCodeAt()\n if (len == 1) {\n if ((y >= 65 && y <= 90) || (y >= 97 && y <= 122)) { return true }\n return false\n }\n if (txt[len - 2] == ' ' && ((y >= 65 && y <= 90) || (y >= 97 && y <= 122))) { return true }\n return false\n}\n\n", "test": "const testCheckIfLastCharIsALetter = () => {\n console.assert(checkIfLastCharIsALetter('apple') === false)\n console.assert(checkIfLastCharIsALetter('apple pi e') === true)\n console.assert(checkIfLastCharIsALetter('eeeee') === false)\n console.assert(checkIfLastCharIsALetter('A') === true)\n console.assert(checkIfLastCharIsALetter('Pumpkin pie ') === false)\n console.assert(checkIfLastCharIsALetter('Pumpkin pie 1') === false)\n console.assert(checkIfLastCharIsALetter('') === false)\n console.assert(checkIfLastCharIsALetter('eeeee e ') === false)\n console.assert(checkIfLastCharIsALetter('apple pie') === false)\n console.assert(checkIfLastCharIsALetter('apple pi e ') === false)\n}\n\ntestCheckIfLastCharIsALetter()\n", "declaration": "\nconst checkIfLastCharIsALetter = (txt) => {\n", "example_test": "const testCheckIfLastCharIsALetter = () => {\n console.assert(checkIfLastCharIsALetter('apple pi e') === true)\n console.assert(checkIfLastCharIsALetter('') === false)\n console.assert(checkIfLastCharIsALetter('apple pie') === false)\n console.assert(checkIfLastCharIsALetter('apple pi e ') === false)\n}\ntestCheckIfLastCharIsALetter()\n", "buggy_solution": " let len = txt.length\n if (len == 0) { return false }\n let y = txt[len - 1].charCodeAt()\n if (len == 1) {\n if ((y >= 0 && y <= 22) || (y >= 30 && y <= 54)) { return true }\n return false\n }\n if (txt[len - 2] == ' ' && ((y >= 150 && y <= 200) || (y >= 250 && y <= 300))) { return true }\n return false\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "CheckIfLastCharIsALetter"} {"task_id": "JavaScript/135", "prompt": "/*Create a function which returns the largest index of an element which\n is not greater than or equal to the element immediately preceding it. If\n no such element exists then return -1. The given array will not contain\n duplicate values.\n\n Examples:\n canArrange([1,2,4,3,5]) = 3\n canArrange([1,2,3]) = -1\n */\nconst canArrange = (arr) => {\n", "canonical_solution": " if (arr.length == 0) { return -1 }\n for (let i = arr.length - 1; i > 0; i--) {\n if (arr[i] < arr[i - 1]) { return i }\n }\n return -1\n}\n\n", "test": "const testCanArrange = () => {\n console.assert(canArrange([1, 2, 4, 3, 5]) === 3)\n console.assert(canArrange([1, 2, 4, 5]) === -1)\n console.assert(canArrange([1, 4, 2, 5, 6, 7, 8, 9, 10]) === 2)\n console.assert(canArrange([4, 8, 5, 7, 3]) === 4)\n console.assert(canArrange([]) === -1)\n}\n\ntestCanArrange()\n", "declaration": "\nconst canArrange = (arr) => {\n", "example_test": "const testCanArrange = () => {\n console.assert(canArrange([1, 2, 4, 3, 5]) === 3)\n console.assert(canArrange([1, 2, 3]) === -1)\n}\ntestCanArrange()\n", "buggy_solution": " if (arr.length == 0) { return -1 }\n for (let i = arr.length - 1; i > 0; i--) {\n if (arr[i] < arr[i - 1]) { return i + arr[i] }\n }\n return -1\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "CanArrange"} {"task_id": "JavaScript/136", "prompt": "/* Create a function that returns a tuple (a, b), where 'a' is\n the largest of negative integers, and 'b' is the smallest\n of positive integers in a list.\n If there is no negative or positive integers, return them as null.\n Examples:\n largestSmallestIntegers([2, 4, 1, 3, 5, 7]) == (null, 1)\n largestSmallestIntegers([]) == (null, null)\n largestSmallestIntegers([0]) == (null, null)\n */\nconst largestSmallestIntegers = (lst) => {\n", "canonical_solution": " let a = Infinity\n let b = -Infinity\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] > 0 && lst[i] < a) { a = lst[i] }\n if (lst[i] < 0 && lst[i] > b) { b = lst[i] }\n }\n if (a == Infinity) { a = null }\n if (b == -Infinity) { b = null }\n return (b, a)\n}\n\n", "test": "const testLargestSmallestIntegers = () => {\n console.assert(\n JSON.stringify(largestSmallestIntegers([2, 4, 1, 3, 5, 7])) ===\n JSON.stringify((null, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([2, 4, 1, 3, 5, 7, 0])) ===\n JSON.stringify((null, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([1, 3, 2, 4, 5, 6, -2])) ===\n JSON.stringify((-2, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([4, 5, 3, 6, 2, 7, -7])) ===\n JSON.stringify((-7, 2))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([7, 3, 8, 4, 9, 2, 5, -9])) ===\n JSON.stringify((-9, 2))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([])) === JSON.stringify((null, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([0])) ===\n JSON.stringify((null, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-1, -3, -5, -6])) ===\n JSON.stringify((-1, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-1, -3, -5, -6, 0])) ===\n JSON.stringify((-1, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-6, -4, -4, -3, 1])) ===\n JSON.stringify((-3, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-6, -4, -4, -3, -100, 1])) ===\n JSON.stringify((-3, 1))\n )\n}\n\ntestLargestSmallestIntegers()\n", "declaration": "\nconst largestSmallestIntegers = (lst) => {\n", "example_test": "const testLargestSmallestIntegers = () => {\n console.assert(\n JSON.stringify(largestSmallestIntegers([2, 4, 1, 3, 5, 7])) ===\n JSON.stringify((null, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([])) === JSON.stringify((null, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([0])) ===\n JSON.stringify((null, null))\n )\n}\ntestLargestSmallestIntegers()\n", "buggy_solution": " let a = Infinity\n let b = -Infinity\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] > 0 && lst[i] < a) { a = lst[i] }\n if (lst[i] < 0 && lst[i] > b) { b = lst[i] }\n if (lst[i] < a && 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"} @@ -152,10 +152,10 @@ {"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/154", "prompt": "/*You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word\n cycpatternCheck(\"abcd\",\"abd\") => false\n cycpatternCheck(\"hello\",\"ell\") => true\n cycpatternCheck(\"whassup\",\"psus\") => false\n cycpatternCheck(\"abab\",\"baa\") => true\n cycpatternCheck(\"efef\",\"eeff\") => false\n cycpatternCheck(\"himenss\",\"simen\") => true\n */\nconst cycpatternCheck = (a, b) => {\n", "canonical_solution": " let l = b.length\n let pat = b + b\n for (let i = 0; i < a.length - l + 1; i++) {\n for (let j = 0; j < l + 1; j++) {\n let y = 1\n for (let k = 0; k < l; k++) {\n if (a[i + k] != pat[j + k]) { y = 0 }\n }\n if (y == 1) {\n return true\n }\n }\n }\n return false\n}\n\n", "test": "const testCycpatternCheck = () => {\n console.assert(cycpatternCheck('xyzw', 'xyw') === false)\n console.assert(cycpatternCheck('yello', 'ell') === true)\n console.assert(cycpatternCheck('whattup', 'ptut') === false)\n console.assert(cycpatternCheck('efef', 'fee') === true)\n console.assert(cycpatternCheck('abab', 'aabb') === false)\n console.assert(cycpatternCheck('winemtt', 'tinem') === true)\n}\n\ntestCycpatternCheck()\n", "declaration": "\nconst cycpatternCheck = (a, b) => {\n", "example_test": "const testCycpatternCheck = () => {\n console.assert(cycpatternCheck('abcd', 'abd') === false)\n console.assert(cycpatternCheck('hello', 'ell') === true)\n console.assert(cycpatternCheck('whassup', 'psus') === false)\n console.assert(cycpatternCheck('abab', 'baa') === true)\n console.assert(cycpatternCheck('efef', 'eeff') === false)\n console.assert(cycpatternCheck('himenss', 'simen') === true)\n}\ntestCycpatternCheck()\n", "buggy_solution": " let l = b.length\n let pat = b + b\n for (let i = 0; i < a.length - l + 1; i++) {\n for (let j = 0; j < b.length - l + 1; j++) {\n let y = 1\n for (let k = 0; k < l; k++) {\n if (a[i + k] != pat[j + k]) { y = 0 }\n }\n if (y == 1) {\n return true\n }\n }\n }\n return false\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "CycpatternCheck"} {"task_id": "JavaScript/155", "prompt": "/*Given an integer. return a tuple that has the number of even and odd digits respectively.\n\n Example:\n evenOddCount(-12) ==> (1, 1)\n evenOddCount(123) ==> (1, 2)\n */\nconst evenOddCount = (num) => {\n", "canonical_solution": " let o = 0\n let e = 0\n if (num < 0) { num = -num }\n while (num > 0) {\n if (num % 2 == 0) { e++ }\n else { o++ }\n num = (num - num % 10) / 10\n }\n return (e, o)\n}\n\n", "test": "const testEvenOddCount = () => {\n console.assert(JSON.stringify(evenOddCount(7)) === JSON.stringify((0, 1)))\n console.assert(JSON.stringify(evenOddCount(-78)) === JSON.stringify((1, 1)))\n console.assert(JSON.stringify(evenOddCount(3452)) === JSON.stringify((2, 2)))\n console.assert(\n JSON.stringify(evenOddCount(346211)) === JSON.stringify((3, 3))\n )\n console.assert(\n JSON.stringify(evenOddCount(-345821)) === JSON.stringify((3, 3))\n )\n console.assert(JSON.stringify(evenOddCount(-2)) === JSON.stringify((1, 0)))\n console.assert(\n JSON.stringify(evenOddCount(-45347)) === JSON.stringify((2, 3))\n )\n console.assert(JSON.stringify(evenOddCount(0)) === JSON.stringify((1, 0)))\n}\n\ntestEvenOddCount()\n", "declaration": "\nconst evenOddCount = (num) => {\n", "example_test": "const testEvenOddCount = () => {\n console.assert(JSON.stringify(evenOddCount(-12)) === JSON.stringify((1, 1)))\n console.assert(JSON.stringify(evenOddCount(123)) === JSON.stringify((1, 2)))\n}\ntestEvenOddCount()\n", "buggy_solution": " let o = 0\n let e = 0\n if (num < 0) { num = -num }\n while (num > 0) {\n if (num % 2 == 0) { e++ }\n else { o++ }\n num = num - num % 10\n }\n return (e, o)\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "EvenOddCount"} {"task_id": "JavaScript/156", "prompt": "/*\n Given a positive integer, obtain its roman numeral equivalent as a string,\n and return it in lowercase.\n Restrictions: 1 <= num <= 1000\n\n Examples:\n >>> intToMiniRoman(19) == 'xix'\n >>> intToMiniRoman(152) == 'clii'\n >>> intToMiniRoman(426) == 'cdxxvi'\n */\nconst intToMiniRoman = (number) => {\n", "canonical_solution": " let num = [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000]\n let sym = ['i', 'iv', 'v', 'ix', 'x', 'xl', 'l', 'xc', 'c', 'cd', 'd', 'cm', 'm']\n let i = 12\n let res = ''\n while (number) {\n let div = (number - number % num[i]) / num[i]\n number = number % num[i]\n while (div) {\n res += sym[i]\n div -= 1\n }\n i -= 1\n }\n return res\n}\n\n", "test": "const testIntToMiniRoman = () => {\n console.assert(intToMiniRoman(19) === 'xix')\n console.assert(intToMiniRoman(152) === 'clii')\n console.assert(intToMiniRoman(251) === 'ccli')\n console.assert(intToMiniRoman(426) === 'cdxxvi')\n console.assert(intToMiniRoman(500) === 'd')\n console.assert(intToMiniRoman(1) === 'i')\n console.assert(intToMiniRoman(4) === 'iv')\n console.assert(intToMiniRoman(43) === 'xliii')\n console.assert(intToMiniRoman(90) === 'xc')\n console.assert(intToMiniRoman(94) === 'xciv')\n console.assert(intToMiniRoman(532) === 'dxxxii')\n console.assert(intToMiniRoman(900) === 'cm')\n console.assert(intToMiniRoman(994) === 'cmxciv')\n console.assert(intToMiniRoman(1000) === 'm')\n}\n\ntestIntToMiniRoman()\n", "declaration": "\nconst intToMiniRoman = (number) => {\n", "example_test": "const testIntToMiniRoman = () => {\n console.assert(intToMiniRoman(19) === 'xix')\n console.assert(intToMiniRoman(152) === 'clii')\n console.assert(intToMiniRoman(426) === 'cdxxvi')\n}\ntestIntToMiniRoman()\n", "buggy_solution": " let num = [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000]\n let sym = ['i', 'iv', 'v', 'ix', 'x', 'xl', 'l', 'xc', 'c', 'cd', 'd', 'cm', 'm']\n let i = 12\n let res = ''\n while (number) {\n let div = (number - number % num[i]) / num[i]\n while (div) {\n res += sym[i]\n div -= 1\n }\n i -= 1\n }\n return res\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "infinite loop", "entry_point": "IntToMiniRoman"} -{"task_id": "JavaScript/157", "prompt": "/*\n Given the lengths of the three sides of a triangle. Return true if the three\n sides form a right-angled triangle, false otherwise.\n A right-angled triangle is a triangle in which one angle is right angle or\n 90 degree.\n Example:\n rightAngleTriangle(3, 4, 5) == true\n rightAngleTriangle(1, 2, 3) == false\n */\nconst rightAngleTriangle = (a, b, c) => {\n", "canonical_solution": " return (a * a + b * b == c * c || a * a == b * b + c * c || b * b == a * a + c * c)\n}\n\n", "test": "const testRightAngleTriangle = () => {\n console.assert(rightAngleTriangle(3, 4, 5) === true)\n console.assert(rightAngleTriangle(1, 2, 3) === false)\n console.assert(rightAngleTriangle(10, 6, 8) === true)\n console.assert(rightAngleTriangle(2, 2, 2) === false)\n console.assert(rightAngleTriangle(7, 24, 25) === true)\n console.assert(rightAngleTriangle(10, 5, 7) === false)\n console.assert(rightAngleTriangle(5, 12, 13) === true)\n console.assert(rightAngleTriangle(15, 8, 17) === true)\n console.assert(rightAngleTriangle(48, 55, 73) === true)\n console.assert(rightAngleTriangle(1, 1, 1) === false)\n console.assert(rightAngleTriangle(2, 2, 10) === false)\n}\n\ntestRightAngleTriangle()\n", "declaration": "\nconst rightAngleTriangle = (a, b, c) => {\n", "example_test": "const testRightAngleTriangle = () => {\n console.assert(rightAngleTriangle(3, 4, 5) === true)\n console.assert(rightAngleTriangle(1, 2, 3) === false)\n}\ntestRightAngleTriangle()\n", "buggy_solution": " return (a * a + b * b == c * c || b * b == a * a + c * c)\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "RightAngleTriangle"} +{"task_id": "JavaScript/157", "prompt": "/*\n Given the lengths of the three sides of a triangle. Return true if the three\n sides form a right-angled triangle, false otherwise.\n A right-angled triangle is a triangle in which one angle is right angle or\n 90 degree.\n Example:\n rightAngleTriangle(3, 4, 5) == true\n rightAngleTriangle(1, 2, 3) == false\n */\nconst rightAngleTriangle = (a, b, c) => {\n", "canonical_solution": " return (a * a + b * b == c * c || a * a == b * b + c * c || b * b == a * a + c * c)\n}\n\n", "test": "const testRightAngleTriangle = () => {\n console.assert(rightAngleTriangle(3, 4, 5) === true)\n console.assert(rightAngleTriangle(1, 2, 3) === false)\n console.assert(rightAngleTriangle(10, 6, 8) === true)\n console.assert(rightAngleTriangle(2, 2, 2) === false)\n console.assert(rightAngleTriangle(7, 24, 25) === true)\n console.assert(rightAngleTriangle(10, 5, 7) === false)\n console.assert(rightAngleTriangle(5, 12, 13) === true)\n console.assert(rightAngleTriangle(15, 8, 17) === true)\n console.assert(rightAngleTriangle(48, 55, 73) === true)\n console.assert(rightAngleTriangle(1, 1, 1) === false)\n console.assert(rightAngleTriangle(2, 2, 10) === false)\n}\n\ntestRightAngleTriangle()\n", "declaration": "\nconst rightAngleTriangle = (a, b, c) => {\n", "example_test": "const testRightAngleTriangle = () => {\n console.assert(rightAngleTriangle(3, 4, 5) === true)\n console.assert(rightAngleTriangle(1, 2, 3) === false)\n}\ntestRightAngleTriangle()\n", "buggy_solution": " return (a * a + b * b == c * c)\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "RightAngleTriangle"} {"task_id": "JavaScript/158", "prompt": "/*Write a function that accepts a list of strings.\n The list contains different words. Return the word with maximum number\n of unique characters. If multiple strings have maximum number of unique\n characters, return the one which comes first in lexicographical order.\n\n findMax([\"name\", \"of\", \"string\"]) === \"string\"\n findMax([\"name\", \"enam\", \"game\"]) === \"enam\"\n findMax([\"aaaaaaa\", \"bb\" ,\"cc\"]) === \"\"aaaaaaa\"\n */\nconst findMax = (words) => {\n", "canonical_solution": " let s = -1\n let u = -1\n if (words.length == 0) { return '' }\n for (let i = 0; i < words.length; i++) {\n let p = 0\n for (let j = 0; j < words[i].length; j++) {\n let y = 1\n for (let k = 0; k < j; k++) {\n if (words[i][j] == words[i][k]) { y = 0 }\n }\n if (y == 1) { p++ }\n }\n if (p > s || (p == s && words[i] < words[u])) {\n u = i;\n s = p;\n }\n }\n return words[u]\n}\n\n", "test": "const testFindMax = () => {\n console.assert(findMax(['name', 'of', 'string']) === 'string')\n console.assert(findMax(['name', 'enam', 'game']) === 'enam')\n console.assert(findMax(['aaaaaaa', 'bb', 'cc']) === 'aaaaaaa')\n console.assert(findMax(['abc', 'cba']) === 'abc')\n console.assert(\n findMax(['play', 'this', 'game', 'of', 'footbott']) === 'footbott'\n )\n console.assert(findMax(['we', 'are', 'gonna', 'rock']) === 'gonna')\n console.assert(findMax(['we', 'are', 'a', 'mad', 'nation']) === 'nation')\n console.assert(findMax(['this', 'is', 'a', 'prrk']) === 'this')\n console.assert(findMax(['b']) === 'b')\n console.assert(findMax(['play', 'play', 'play']) === 'play')\n}\n\ntestFindMax()\n", "declaration": "\nconst findMax = (words) => {\n", "example_test": "const testFindMax = () => {\n console.assert(findMax(['name', 'of', 'string']) === 'string')\n console.assert(findMax(['name', 'enam', 'game']) === 'enam')\n console.assert(findMax(['aaaaaaa', 'bb', 'cc']) === 'aaaaaaa')\n}\ntestFindMax()\n", "buggy_solution": " let s = -1\n let u = -1\n if (words.length == 0) { return '' }\n for (let i = 0; i < words.length; i++) {\n let p = 0\n for (let j = 0; j < words[i].length; j++) {\n let y = 1\n for (let k = 0; k < j; k++) {\n if (words[i][j] == words[i][k]) { y = 0 }\n }\n }\n if (p > s || (p == s && words[i] < words[u])) {\n u = i;\n s = p;\n }\n }\n return words[u]\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "FindMax"} {"task_id": "JavaScript/159", "prompt": "/*\n You're a hungry rabbit, and you already have eaten a certain number of carrots,\n but now you need to eat more carrots to complete the day's meals.\n you should return an array of [ total number of eaten carrots after your meals,\n the number of carrots left after your meals ]\n if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.\n \n Example:\n * eat(5, 6, 10) -> [11, 4]\n * eat(4, 8, 9) -> [12, 1]\n * eat(1, 10, 10) -> [11, 0]\n * eat(2, 11, 5) -> [7, 0]\n \n Variables:\n @number : integer\n the number of carrots that you have eaten.\n @need : integer\n the number of carrots that you need to eat.\n @remaining : integer\n the number of remaining carrots thet exist in stock\n \n Constrain:\n * 0 <= number <= 1000\n * 0 <= need <= 1000\n * 0 <= remaining <= 1000\n\n Have fun :)\n */\nconst eat = (number, need, remaining) => {\n", "canonical_solution": " if (need <= remaining) {\n return [need + number, remaining - need]\n }\n return [remaining + number, 0]\n}\n\n", "test": "const testEat = () => {\n console.assert(JSON.stringify(eat(5, 6, 10)) === JSON.stringify([11, 4]))\n console.assert(JSON.stringify(eat(4, 8, 9)) === JSON.stringify([12, 1]))\n console.assert(JSON.stringify(eat(1, 10, 10)) === JSON.stringify([11, 0]))\n console.assert(JSON.stringify(eat(2, 11, 5)) === JSON.stringify([7, 0]))\n console.assert(JSON.stringify(eat(4, 5, 7)) === JSON.stringify([9, 2]))\n console.assert(JSON.stringify(eat(4, 5, 1)) === JSON.stringify([5, 0]))\n}\n\ntestEat()\n", "declaration": "\nconst eat = (number, need, remaining) => {\n", "example_test": "const testEat = () => {\n console.assert(JSON.stringify(eat(5, 6, 10)) === JSON.stringify([11, 4]))\n console.assert(JSON.stringify(eat(4, 8, 9)) === JSON.stringify([12, 1]))\n console.assert(JSON.stringify(eat(1, 10, 10)) === JSON.stringify([11, 0]))\n console.assert(JSON.stringify(eat(2, 11, 5)) === JSON.stringify([7, 0]))\n}\ntestEat()\n", "buggy_solution": " if (need <= remaining) {\n return [need + number, number + remaining - need]\n }\n return [remaining + need + number, 0]\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Eat"} {"task_id": "JavaScript/160", "prompt": "/*\n Given two lists operator, and operand. The first list has basic algebra operations, and \n the second list is a list of integers. Use the two given lists to build the algebric \n expression and return the evaluation of this expression.\n\n The basic algebra operations:\n Addition ( + ) \n Subtraction ( - ) \n Multiplication ( * ) \n Floor division ( // ) \n Exponentiation ( ** ) \n\n Example:\n operator['+', '*', '-']\n array = [2, 3, 4, 5]\n result = 2 + 3 * 4 - 5\n => result = 9\n\n Note:\n The length of operator list is equal to the length of operand list minus one.\n Operand is a list of of non-negative integers.\n Operator list has at least one operator, and operand list has at least two operands.\n\n */\nconst doAlgebra = (operator, operand) => {\n", "canonical_solution": " while (operator.length > 0) {\n let y = 0\n for (let i = operator.length - 1; i >= 0; i--) {\n if (operator[i] == '**') {\n let u = operand[i]\n while (operand[i + 1] > 1) {\n operand[i + 1]--;\n operand[i] *= u;\n }\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n for (let i = 0; i < operator.length; i++) {\n if (operator[i] == '*') {\n operand[i] *= operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n else if (operator[i] == '//') {\n operand[i] = (operand[i] - operand[i] % operand[i + 1]) / operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n for (let i = 0; i < operator.length; i++) {\n if (operator[i] == '+') {\n operand[i] += operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n else if (operator[i] == '-') {\n operand[i] -= operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n }\n return operand[0]\n}\n\n", "test": "const testDoAlgebra = () => {\n console.assert(doAlgebra(['**', '*', '+'], [2, 3, 4, 5]) === 37)\n console.assert(doAlgebra(['+', '*', '-'], [2, 3, 4, 5]) === 9)\n console.assert(doAlgebra(['//', '*'], [7, 3, 4]) === 8)\n}\n\ntestDoAlgebra()\n", "declaration": "\nconst doAlgebra = (operator, operand) => {\n", "example_test": "", "buggy_solution": " while (operator.length > 0) {\n let y = 0\n for (let i = operator.length - 1; i >= 0; i--) {\n if (operator[i] == '**') {\n let u = operand[i]\n while (operand[i + 1] > 1) {\n operand[i + 1]--;\n operand[i] *= u;\n }\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n for (let i = 0; i < operator.length; i++) {\n if (operator[i] == '*') {\n operand[i] *= operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n else if (operator[i] == '//') {\n operand[i] = (operand[i + 1] - operand[i] % operand[i + 1]) / operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n for (let i = 0; i < operator.length; i++) {\n if (operator[i] == '+') {\n operand[i] += operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n else if (operator[i] == '-') {\n operand[i] -= operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n }\n return operand[0]\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "DoAlgebra"}