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" @@ -30,7 +30,7 @@ {"task_id": "JavaScript/29", "prompt": "/* Filter an input list of strings only for ones that start with a given prefix.\n >>> filterByPrefix([], 'a')\n []\n >>> filterByPrefix(['abc', 'bcd', 'cde', 'array'], 'a')\n ['abc', 'array']\n */\nconst filterByPrefix = (strings, prefix) => {\n", "canonical_solution": " return strings.filter(x => x.startsWith(prefix));\n}\n\n", "test": "const testFilterByPrefix = () => {\n console.assert(\n JSON.stringify(filterByPrefix([], 'john')) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(\n filterByPrefix(['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'], 'xxx')\n ) === JSON.stringify(['xxx', 'xxxAAA', 'xxx'])\n )\n}\n\ntestFilterByPrefix()\n", "declaration": "\nconst filterByPrefix = (strings, prefix) => {\n", "example_test": "const testFilterByPrefix = () => {\n console.assert(\n JSON.stringify(filterByPrefix([], 'a')) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(\n filterByPrefix(['abc', 'bcd', 'cde', 'array'], 'a')\n ) === JSON.stringify(['abc', 'array'])\n )\n}\ntestFilterByPrefix()\n", "buggy_solution": " return strings.filter(x => x.endsWith(prefix));\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "FilterByPrefix"} {"task_id": "JavaScript/30", "prompt": "/*Return only positive numbers in the list.\n >>> getPositive([-1, 2, -4, 5, 6])\n [2, 5, 6]\n >>> getPositive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n [5, 3, 2, 3, 9, 123, 1]\n */\nconst getPositive = (l) => {\n", "canonical_solution": " return l.filter(e => e > 0);\n}\n\n", "test": "const testGetPositive = () => {\n console.assert(\n JSON.stringify(getPositive([-1, -2, 4, 5, 6])) === JSON.stringify([4, 5, 6])\n )\n console.assert(\n JSON.stringify(getPositive([5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10])) ===\n JSON.stringify([5, 3, 2, 3, 3, 9, 123, 1])\n )\n console.assert(JSON.stringify(getPositive([-1, -2])) === JSON.stringify([]))\n console.assert(JSON.stringify(getPositive([])) === JSON.stringify([]))\n}\n\ntestGetPositive()\n", "declaration": "\nconst getPositive = (l) => {\n", "example_test": "const testGetPositive = () => {\n console.assert(\n JSON.stringify(getPositive([-1, 2, -4, 5, 6])) === JSON.stringify([2, 5, 6])\n )\n console.assert(\n JSON.stringify(getPositive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) ===\n JSON.stringify([5, 3, 2, 3, 9, 123, 1])\n )\n}\ntestGetPositive()\n", "buggy_solution": " return l.filter(e => e < 0);\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "GetPositive"} {"task_id": "JavaScript/31", "prompt": "/*Return true if a given number is prime, and false otherwise.\n >>> isPrime(6)\n false\n >>> isPrime(101)\n true\n >>> isPrime(11)\n true\n >>> isPrime(13441)\n true\n >>> isPrime(61)\n true\n >>> isPrime(4)\n false\n >>> isPrime(1)\n false\n */\nconst isPrime = (n) => {\n", "canonical_solution": " if (n < 2)\n return false;\n for (let k = 2; k < n - 1; k++)\n if (n % k == 0)\n return false;\n return true;\n}\n\n", "test": "const testIsPrime = () => {\n console.assert(isPrime(6) === false)\n console.assert(isPrime(101) === true)\n console.assert(isPrime(11) === true)\n console.assert(isPrime(13441) === true)\n console.assert(isPrime(61) === true)\n console.assert(isPrime(4) === false)\n console.assert(isPrime(1) === false)\n console.assert(isPrime(5) === true)\n console.assert(isPrime(11) === true)\n console.assert(isPrime(17) === true)\n console.assert(isPrime(5 * 17) === false)\n console.assert(isPrime(11 * 7) === false)\n console.assert(isPrime(13441 * 19) === false)\n}\n\ntestIsPrime()\n", "declaration": "\nconst isPrime = (n) => {\n", "example_test": "const testIsPrime = () => {\n console.assert(isPrime(6) === false)\n console.assert(isPrime(101) === true)\n console.assert(isPrime(11) === true)\n console.assert(isPrime(13441) === true)\n console.assert(isPrime(61) === true)\n console.assert(isPrime(4) === false)\n console.assert(isPrime(1) === false)\n}\ntestIsPrime()\n", "buggy_solution": " if (n < 1)\n return false;\n for (let k = 1; k < n - 1; k++)\n if (n % k == 0)\n return false;\n return true;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "IsPrime"} -{"task_id": "JavaScript/32", "prompt": "/*\n Evaluates polynomial with coefficients xs at point x.\n return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n\n */\nconst poly = (xs, x) => {\n return xs.reduce((prev, item, index) => {\n return prev + item * Math.pow(x, index);\n }, 0);\n}\n\n/*\n xs are coefficients of a polynomial.\n findZero find x such that poly(x) = 0.\n findZero returns only only zero point, even if there are many.\n Moreover, findZero only takes list xs having even number of coefficients\n and largest non zero coefficient as it guarantees\n a solution.\n >>> round(findZero([1, 2]), 2) # f(x) = 1 + 2x\n -0.5\n >>> round(findZero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3\n 1.0\n */\nconst findZero = (xs) => {\n", "canonical_solution": " var begin = -1.0, end = 1.0;\n while (poly(xs, begin) * poly(xs, end) > 0) {\n begin *= 2.0;\n end *= 2.0;\n }\n while (end - begin > 1e-10) {\n let center = (begin + end) / 2.0;\n if (poly(xs, center) * poly(xs, begin) > 0)\n begin = center;\n else\n end = center;\n }\n return begin;\n}\n\n", "test": "const testfindZero = () => {\n const getRandomIntInclusive = (min = 0, max = 9) => {\n min = Math.ceil(min)\n max = Math.floor(max)\n return Math.floor(Math.random() * (max - min + 1)) + min\n }\n\n for (let i = 0; i < 100; i++) {\n let ncoeff = 2 * getRandomIntInclusive(1, 4);\n let coeffs = [];\n for (let j = 0; j < ncoeff; j++) {\n let coeff = getRandomIntInclusive(-10, 10);\n if (coeff === 0)\n coeff = 1;\n coeffs.push(coeff);\n }\n let solution = findZero(coeffs);\n console.assert(Math.abs(poly(coeffs, solution)) < 1e-4);\n }\n}\n", "declaration": "\nconst poly = (xs, x) => {\n return xs.reduce((prev, item, index) => {\n return prev + item * Math.pow(x, index);\n }, 0);\n}\n\nconst findZero = (xs) => {\n", "example_test": "const testPoly = () => {\n console.assert(Math.abs(findZero([1,2])+0.5 < 1e-4));\n console.assert(Math.abs(findZero([-6,11,-6,1])-1 < 1e-4));\n}\ntestPoly()\n", "buggy_solution": " var begin = -1.0, end = 1.0;\n while (poly(xs, begin) * poly(xs, end) > 0) {\n begin *= 2.0;\n end *= 2.0;\n }\n while (begin - end > 1e-10) {\n let center = (begin + end) / 2.0;\n if (poly(xs, center) * poly(xs, begin) > 0)\n begin = center;\n else\n end = center;\n }\n return begin;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "FindZero"} +{"task_id": "JavaScript/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, end) > 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 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"} @@ -89,7 +89,7 @@ {"task_id": "JavaScript/88", "prompt": "/*\n Given an array of non-negative integers, return a copy of the given array after sorting,\n you will sort the given array in ascending order if the sum( first index value, last index value) is odd,\n or sort it in descending order if the sum( first index value, last index value) is even.\n\n Note:\n * don't change the given array.\n\n Examples:\n * sortArray([]) => []\n * sortArray([5]) => [5]\n * sortArray([2, 4, 3, 0, 1, 5]) => [0, 1, 2, 3, 4, 5]\n * sortArray([2, 4, 3, 0, 1, 5, 6]) => [6, 5, 4, 3, 2, 1, 0]\n */\nconst sortArray = (array) => {\n", "canonical_solution": " let arr = array\n let tot = arr[0] + arr[arr.length-1]\n for (let j = 0; j < arr.length; j++) {\n let ind = j\n for (let k = j + 1; k < arr.length; k++) {\n if ((tot % 2 == 1 && arr[k] < arr[ind]) || (tot % 2 == 0 && arr[k] > arr[ind])) {\n ind = k\n }\n }\n let tmp = arr[j]\n arr[j] = arr[ind]\n arr[ind] = tmp\n }\n return arr\n}\n\n", "test": "const testSortArray = () => {\n console.assert(JSON.stringify(sortArray([])) === JSON.stringify([]))\n console.assert(JSON.stringify(sortArray([5])) === JSON.stringify([5]))\n console.assert(JSON.stringify(sortArray([2, 4, 3, 0, 1, 5])) === JSON.stringify([0, 1, 2, 3, 4, 5]))\n console.assert(JSON.stringify(sortArray([2, 4, 3, 0, 1, 5, 6])) === JSON.stringify([6, 5, 4, 3, 2, 1, 0]))\n console.assert(JSON.stringify(sortArray([2, 1])) === JSON.stringify([1, 2]))\n console.assert(JSON.stringify(sortArray([15, 42, 87, 32, 11, 0])) === JSON.stringify([0, 11, 15, 32, 42, 87]))\n console.assert(JSON.stringify(sortArray([21, 14, 23, 11])) === JSON.stringify([23, 21, 14, 11]))\n}\n\ntestSortArray()\n", "declaration": "\nconst sortArray = (array) => {\n", "example_test": "const testSortArray = () => {\n console.assert(JSON.stringify(sortArray([])) === JSON.stringify([]))\n console.assert(JSON.stringify(sortArray([5])) === JSON.stringify([5]))\n console.assert(JSON.stringify(sortArray([2, 4, 3, 0, 1, 5])) === JSON.stringify([0, 1, 2, 3, 4, 5]))\n console.assert(JSON.stringify(sortArray([2, 4, 3, 0, 1, 5, 6])) === JSON.stringify([6, 5, 4, 3, 2, 1, 0]))\n}\ntestSortArray()\n", "buggy_solution": " let arr = array\n let tot = arr[0] + arr[arr.length-1]\n for (let j = 0; j < arr.length; j++) {\n let ind = j\n for (let k = j + 1; k < arr.length; k++) {\n if ((tot % 2 == 1 && arr[k] < arr[ind]) || (tot % 2 != 0 && arr[k] > arr[ind])) {\n ind = k\n }\n }\n let tmp = arr[j]\n arr[j] = arr[ind]\n arr[ind] = tmp\n }\n return arr\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "SortArray"} {"task_id": "JavaScript/89", "prompt": "/*Create a function encrypt that takes a string as an argument and\n returns a string encrypted with the alphabet being rotated. \n The alphabet should be rotated in a manner such that the letters \n shift down by two multiplied to two places.\n For example:\n encrypt('hi') returns 'lm'\n encrypt('asdfghjkl') returns 'ewhjklnop'\n encrypt('gf') returns 'kj'\n encrypt('et') returns 'ix'\n */\nconst encrypt = (s) => {\n", "canonical_solution": " let t = ''\n for (let i = 0; i < s.length; i++) {\n let p = s[i].charCodeAt() + 4\n if (p > 122) { p -= 26 }\n t += String.fromCharCode(p)\n }\n return t\n}\n\n", "test": "const testEncrypt = () => {\n console.assert(encrypt('hi') === 'lm')\n console.assert(encrypt('asdfghjkl') === 'ewhjklnop')\n console.assert(encrypt('gf') === 'kj')\n console.assert(encrypt('et') === 'ix')\n console.assert(encrypt('faewfawefaewg') === 'jeiajeaijeiak')\n console.assert(encrypt('hellomyfriend') === 'lippsqcjvmirh')\n console.assert(\n encrypt('dxzdlmnilfuhmilufhlihufnmlimnufhlimnufhfucufh') ===\n 'hbdhpqrmpjylqmpyjlpmlyjrqpmqryjlpmqryjljygyjl'\n )\n console.assert(encrypt('a') === 'e')\n}\n\ntestEncrypt()\n", "declaration": "\nconst encrypt = (s) => {\n", "example_test": "const testEncrypt = () => {\n console.assert(encrypt('hi') === 'lm')\n console.assert(encrypt('asdfghjkl') === 'ewhjklnop')\n console.assert(encrypt('gf') === 'kj')\n console.assert(encrypt('et') === 'ix')\n}\ntestEncrypt()\n", "buggy_solution": " let t = ''\n for (let i = 0; i < s.length; i++) {\n let p = s[i].charCodeAt() + 4\n if (p > 122) { p -= 24 }\n t += String.fromCharCode(p)\n }\n return t\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Encrypt"} {"task_id": "JavaScript/90", "prompt": "/*\n You are given a list of integers.\n Write a function nextSmallest() that returns the 2nd smallest element of the list.\n Return null if there is no such element.\n \n nextSmallest([1, 2, 3, 4, 5]) == 2\n nextSmallest([5, 1, 4, 3, 2]) == 2\n nextSmallest([]) == null\n nextSmallest([1, 1]) == null\n */\nconst nextSmallest = (lst) => {\n", "canonical_solution": " let arr = lst\n for (let j = 0; j < arr.length; j++) {\n let ind = j\n for (let k = j + 1; k < arr.length; k++) {\n if (arr[k] < arr[ind]) {\n ind = k\n }\n }\n let tmp = arr[j]\n arr[j] = arr[ind]\n arr[ind] = tmp\n }\n let smallest = arr[0]\n let pt = 1\n while(ptsmallest){\n return arr[pt]\n }\n pt++\n }\n return null\n}\n\n", "test": "const testNextSmallest = () => {\n console.assert(nextSmallest([1, 2, 3, 4, 5]) === 2)\n console.assert(nextSmallest([5, 1, 4, 3, 2]) === 2)\n console.assert(nextSmallest([]) === null)\n console.assert(nextSmallest([1, 1]) === null)\n console.assert(nextSmallest([1, 1, 1, 1, 0]) === 1)\n console.assert(nextSmallest([1, 0 ** 0]) === null)\n console.assert(nextSmallest([-35, 34, 12, -45]) === -35)\n}\n\ntestNextSmallest()\n", "declaration": "\nconst nextSmallest = (lst) => {\n", "example_test": "const testNextSmallest = () => {\n console.assert(nextSmallest([1, 2, 3, 4, 5]) === 2)\n console.assert(nextSmallest([5, 1, 4, 3, 2]) === 2)\n console.assert(nextSmallest([]) === null)\n console.assert(nextSmallest([1, 1]) === null)\n}\ntestNextSmallest()\n", "buggy_solution": " let arr = lst\n for (let j = 0; j < arr.length; j++) {\n let ind = j\n for (let k = j + 1; k < arr.length; k++) {\n if (arr[k] < arr[ind]) {\n ind = k\n }\n }\n let tmp = arr[j]\n arr[j] = arr[ind]\n arr[ind] = tmp\n }\n let smallest = 0\n let pt = 0\n while(ptsmallest){\n return arr[pt]\n }\n pt++\n }\n return null\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "NextSmallest"} -{"task_id": "JavaScript/91", "prompt": "/*\n You'll be given a string of words, and your task is to count the number\n of boredoms. A boredom is a sentence that starts with the word \"I\".\n Sentences are delimited by '.', '?' or '!'.\n \n For example:\n >>> isBored(\"Hello world\")\n 0\n >>> isBored(\"The sky is blue. The sun is shining. I love this weather\")\n 1\n */\nconst isBored = (S) => {\n", "canonical_solution": " let t = 0\n if (S[0] == 'I' && S[1] == ' ') { t = 1 }\n for (let i = 0; i < S.length; i++) {\n if (S[i] == '.' || S[i] == '!' || S[i] == '?') {\n if (S[i + 1] == ' ' && S[i + 2] == 'I' && S[i + 3] == ' ') {\n t++\n }\n }\n }\n return t\n}\n\n", "test": "const testIsBored = () => {\n console.assert(isBored('Hello world') === 0)\n console.assert(isBored('Is the sky blue?') === 0)\n console.assert(isBored('I love It !') === 1)\n console.assert(isBored('bIt') === 0)\n console.assert(\n isBored('I feel good today. I will be productive. will kill It') === 2\n )\n console.assert(isBored('You and I are going for a walk') === 0)\n}\n\ntestIsBored()\n", "declaration": "\nconst isBored = (S) => {\n", "example_test": "const testIsBored = () => {\n console.assert(isBored('Hello world') === 0)\n console.assert(isBored('The sky is blue. The sun is shining. I love this weather') === 1)\n}\ntestIsBored()\n", "buggy_solution": " let t = 0\n if (S[1] == ' ' && S[0] == 'I') { t = 1 }\n for (let i = 0; i < S.length; i++) {\n if (S[i] == '.' || S[i] == '!' || S[i] == '?') {\n if (S[i + 1] == ' ' && S[i + 2] == 'I' && S[i + 3] == ' ') {\n t++\n }\n }\n }\n return t\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "IsBored"} +{"task_id": "JavaScript/91", "prompt": "/*\n You'll be given a string of words, and your task is to count the number\n of boredoms. A boredom is a sentence that starts with the word \"I\".\n Sentences are delimited by '.', '?' or '!'.\n \n For example:\n >>> isBored(\"Hello world\")\n 0\n >>> isBored(\"The sky is blue. The sun is shining. I love this weather\")\n 1\n */\nconst isBored = (S) => {\n", "canonical_solution": " let t = 0\n if (S[0] == 'I' && S[1] == ' ') { t = 1 }\n for (let i = 0; i < S.length; i++) {\n if (S[i] == '.' || S[i] == '!' || S[i] == '?') {\n if (S[i + 1] == ' ' && S[i + 2] == 'I' && S[i + 3] == ' ') {\n t++\n }\n }\n }\n return t\n}\n\n", "test": "const testIsBored = () => {\n console.assert(isBored('Hello world') === 0)\n console.assert(isBored('Is the sky blue?') === 0)\n console.assert(isBored('I love It !') === 1)\n console.assert(isBored('bIt') === 0)\n console.assert(\n isBored('I feel good today. I will be productive. will kill It') === 2\n )\n console.assert(isBored('You and I are going for a walk') === 0)\n}\n\ntestIsBored()\n", "declaration": "\nconst isBored = (S) => {\n", "example_test": "const testIsBored = () => {\n console.assert(isBored('Hello world') === 0)\n console.assert(isBored('The sky is blue. The sun is shining. I love this weather') === 1)\n}\ntestIsBored()\n", "buggy_solution": " let t = 0\n if (S[0] == ' ' && S[1] == 'I') { t = 1 }\n for (let i = 0; i < S.length; i++) {\n if (S[i] == '.' || S[i] == '!' || S[i] == '?') {\n if (S[i + 1] == ' ' && S[i + 2] == 'I' && S[i + 3] == ' ') {\n t++\n }\n }\n }\n return t\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "IsBored"} {"task_id": "JavaScript/92", "prompt": "/* Create a function that takes 3 numbers.\n Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.\n Returns false in any other cases.\n Examples\n anyInt(5, 2, 7) \u279e true\n anyInt(3, 2, 2) \u279e false\n anyInt(3, -2, 1) \u279e true\n anyInt(3.6, -2.2, 2) \u279e false\n */\nconst anyInt = (x, y, z) => {\n", "canonical_solution": " if (x % 1 === 0 && y % 1 === 0 && z % 1 === 0 && (x + y === z || x + z === y || x === y + z)) {\n return true\n }\n return false\n}\n\n", "test": "const testAnyInt = () => {\n console.assert(anyInt(2, 3, 1) === true)\n console.assert(anyInt(2.5, 2, 3) === false)\n console.assert(anyInt(1.5, 5, 3.5) === false)\n console.assert(anyInt(2, 6, 2) === false)\n console.assert(anyInt(4, 2, 2) === true)\n console.assert(anyInt(2.2, 2.2, 2.2) === false)\n console.assert(anyInt(-4, 6, 2) === true)\n console.assert(anyInt(2, 1, 1) === true)\n console.assert(anyInt(3, 4, 7) === true)\n console.assert(anyInt(3.0, 4, 7) === true)\n}\n\ntestAnyInt()\n", "declaration": "\nconst anyInt = (x, y, z) => {\n", "example_test": "const testAnyInt = () => {\n console.assert(anyInt(5, 2, 7) === true)\n console.assert(anyInt(3, 2, 2) === false)\n console.assert(anyInt(3, -2, 1) === true)\n console.assert(anyInt(3.6, -2.2, 2) === false)\n}\ntestAnyInt()\n", "buggy_solution": " if (x % 1 === 0 && y % 1 === 0 && z % 1 === 0 && (x + y === z || x === y + z)) {\n return true\n }\n return false\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "AnyInt"} {"task_id": "JavaScript/93", "prompt": "/*\n Write a function that takes a message, and encodes in such a \n way that it swaps case of all letters, replaces all vowels in \n the message with the letter that appears 2 places ahead of that \n vowel in the english alphabet. \n Assume only letters. \n \n Examples:\n >>> encode('test')\n 'TGST'\n >>> encode('This is a message')\n 'tHKS KS C MGSSCGG'\n */\nconst encode = (message) => {\n", "canonical_solution": " let t = ''\n for (let i = 0; i < message.length; i++) {\n let p = message[i].charCodeAt()\n if (p > 96) { p -= 32 }\n else if (p!=32 && p < 96) { p += 32 }\n if (p == 65 || p == 97 || p == 69 || p == 101 || p == 73 || p == 105 || p == 79 || p == 111 || p == 85 || p == 117) { p += 2 }\n t += String.fromCharCode(p)\n }\n return t\n}\n\n", "test": "const testEncode = () => {\n console.assert(encode('TEST') === 'tgst')\n console.assert(encode('Mudasir') === 'mWDCSKR')\n console.assert(encode('YES') === 'ygs')\n console.assert(encode('This is a message') === 'tHKS KS C MGSSCGG')\n console.assert(\n encode('I DoNt KnOw WhAt tO WrItE') === 'k dQnT kNqW wHcT Tq wRkTg'\n )\n}\n\ntestEncode()\n", "declaration": "\nconst encode = (message) => {\n", "example_test": "const testEncode = () => {\n console.assert(encode('test') === 'TGST')\n console.assert(encode('This is a message') === 'tHKS KS C MGSSCGG')\n}\ntestEncode()\n", "buggy_solution": " let t = ''\n for (let i = 0; i < message.length; i++) {\n let p = message[i].charCodeAt()\n if (p > 96) { p -= 32 }\n else if (p!=32 && p < 96) { p += 32 }\n if (p == 65 || p == 97 || p == 69 || p == 101 || p == 73 || p == 105 || p == 79 || p == 111 || p == 85 || p == 117) { p += 2 }\n }\n return t\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "Encode"} {"task_id": "JavaScript/94", "prompt": "/*You are given a list of integers.\n You need to find the largest prime value and return the sum of its digits.\n\n Examples:\n For lst = [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3] the output should be 10\n For lst = [1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1] the output should be 25\n For lst = [1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3] the output should be 13\n For lst = [0,724,32,71,99,32,6,0,5,91,83,0,5,6] the output should be 11\n For lst = [0,81,12,3,1,21] the output should be 3\n For lst = [0,8,1,2,1,7] the output should be 7\n */\nconst skjkasdkd = (lst) => {\n", "canonical_solution": " let t = 0\n for (let i = 0; i < lst.length; i++) {\n let p = 1\n for (let j = 2; j * j <= lst[i]; j++) {\n if (lst[i] % j == 0) { p = 0; break }\n }\n if (p == 1 && lst[i] > t) { t = lst[i] }\n }\n let k = 0\n while (t != 0) {\n k += t % 10\n t = (t - t % 10) / 10\n }\n return k\n}\n\n", "test": "const testSkjkasdkd = () => {\n console.assert(\n skjkasdkd([\n 0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3,\n ]) === 10\n )\n\n console.assert(\n skjkasdkd([1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) === 25\n )\n\n console.assert(\n skjkasdkd([\n 1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3,\n ]) === 13\n )\n\n console.assert(\n skjkasdkd([0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) === 11\n )\n\n console.assert(skjkasdkd([0, 81, 12, 3, 1, 21]) === 3)\n\n console.assert(skjkasdkd([0, 8, 1, 2, 1, 7]) === 7)\n\n console.assert(skjkasdkd([8191]) === 19)\n console.assert(skjkasdkd([8191, 123456, 127, 7]) === 19)\n console.assert(skjkasdkd([127, 97, 8192]) === 10)\n}\n\ntestSkjkasdkd()\n", "declaration": "\nconst skjkasdkd = (lst) => {\n", "example_test": "const testSkjkasdkd = () => {\n console.assert(\n skjkasdkd([\n 0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3,\n ]) === 10\n )\n console.assert(\n skjkasdkd([1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) === 25\n )\n console.assert(\n skjkasdkd([\n 1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3,\n ]) === 13\n )\n console.assert(\n skjkasdkd([0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) === 11\n )\n console.assert(skjkasdkd([0, 81, 12, 3, 1, 21]) === 3)\n console.assert(skjkasdkd([0, 8, 1, 2, 1, 7]) === 7)\n}\ntestSkjkasdkd()\n", "buggy_solution": " let t = 0\n for (let i = 0; i < lst.length; i++) {\n let p = 1\n for (let j = 2; j * j <= lst[i]; j++) {\n if (lst[i] % j == 0) { p = 0; break }\n }\n if (p == 1 || lst[i] > t) { t = lst[i] }\n }\n let k = 0\n while (t != 0) {\n k += t % 10\n t = (t - t % 10) / 10\n }\n return k\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "Skjkasdkd"} @@ -110,14 +110,14 @@ {"task_id": "JavaScript/109", "prompt": "/*We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The\n numbers in the array will be randomly ordered. Your task is to determine if\n it is possible to get an array sorted in non-decreasing order by performing \n the following operation on the given array:\n You are allowed to perform right shift operation any number of times.\n \n One right shift operation means shifting all elements of the array by one\n position in the right direction. The last element of the array will be moved to\n the starting position in the array i.e. 0th index. \n\n If it is possible to obtain the sorted array by performing the above operation\n then return true else return false.\n If the given array is empty then return true.\n\n Note: The given list is guaranteed to have unique elements.\n\n For Example:\n \n moveOneBall([3, 4, 5, 1, 2])==>true\n Explanation: By performin 2 right shift operations, non-decreasing order can\n be achieved for the given array.\n moveOneBall([3, 5, 4, 1, 2])==>false\n Explanation:It is not possible to get non-decreasing order for the given\n array by performing any number of right shift operations.\n \n */\nconst moveOneBall = (arr) => {\n", "canonical_solution": " if (arr.length == 0) { return true }\n let k = 0\n let len = arr.length\n for (let i = 0; i < len; i++) {\n let t = 1;\n for (let j = 1; j < len; j++) {\n if (arr[j] < arr[j - 1]) {\n t = 0;\n break;\n }\n }\n if (t == 1) {\n k = 1;\n break;\n }\n arr.push(arr[0]);\n arr.shift()\n }\n if (k == 1) { return true }\n return false\n}\n\n", "test": "const testMoveOneBall = () => {\n console.assert(moveOneBall([3, 4, 5, 1, 2]) === true)\n console.assert(moveOneBall([3, 5, 10, 1, 2]) === true)\n console.assert(moveOneBall([4, 3, 1, 2]) === false)\n console.assert(moveOneBall([3, 5, 4, 1, 2]) === false)\n console.assert(moveOneBall([]) === true)\n}\n\ntestMoveOneBall()\n", "declaration": "\nconst moveOneBall = (arr) => {\n", "example_test": "const testMoveOneBall = () => {\n console.assert(moveOneBall([3, 4, 5, 1, 2]) === true)\n console.assert(moveOneBall([3, 5, 4, 1, 2]) === false)\n}\ntestMoveOneBall()\n", "buggy_solution": " if (arr.length == 0) { return true }\n let k = 0\n let len = arr.length\n for (let i = 0; i < len; i++) {\n let t = 1;\n for (let j = 1; j < len; j++) {\n if (arr[j] < arr[j - 1]) {\n t = 0;\n break;\n }\n }\n if (t == 1) {\n k = 1;\n break;\n }\n arr.push(arr[j]);\n arr.shift()\n }\n if (k == 1) { return true }\n return false\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "MoveOneBall"} {"task_id": "JavaScript/110", "prompt": "/*In this problem, you will implement a function that takes two lists of numbers,\n and determines whether it is possible to perform an exchange of elements\n between them to make lst1 a list of only even numbers.\n There is no limit on the number of exchanged elements between lst1 and lst2.\n If it is possible to exchange elements between the lst1 and lst2 to make\n all the elements of lst1 to be even, return \"YES\".\n Otherwise, return \"NO\".\n For example:\n exchange([1, 2, 3, 4], [1, 2, 3, 4]) => \"YES\"\n exchange([1, 2, 3, 4], [1, 5, 3, 4]) => \"NO\"\n It is assumed that the input lists will be non-empty.\n */\nconst exchange = (lst1, lst2) => {\n", "canonical_solution": " let k = lst1.length\n let t = 0\n for (let i = 0; i < lst1.length; i++) {\n if (lst1[i] % 2 == 0) { t++ }\n }\n for (let i = 0; i < lst2.length; i++) {\n if (lst2[i] % 2 == 0) { t++ }\n }\n if (t >= k) { return 'YES' }\n return 'NO'\n}\n\n", "test": "const testExchange = () => {\n console.assert(exchange([1, 2, 3, 4], [1, 2, 3, 4]) === 'YES')\n console.assert(exchange([1, 2, 3, 4], [1, 5, 3, 4]) === 'NO')\n console.assert(exchange([1, 2, 3, 4], [2, 1, 4, 3]) === 'YES')\n console.assert(exchange([5, 7, 3], [2, 6, 4]) === 'YES')\n console.assert(exchange([5, 7, 3], [2, 6, 3]) === 'NO')\n console.assert(exchange([3, 2, 6, 1, 8, 9], [3, 5, 5, 1, 1, 1]) === 'NO')\n console.assert(exchange([100, 200], [200, 200]) === 'YES')\n}\n\ntestExchange()\n", "declaration": "\nconst exchange = (lst1, lst2) => {\n", "example_test": "const testExchange = () => {\n console.assert(exchange([1, 2, 3, 4], [1, 2, 3, 4]) === 'YES')\n console.assert(exchange([1, 2, 3, 4], [1, 5, 3, 4]) === 'NO')\n}\ntestExchange()\n", "buggy_solution": " let k = lst1.length\n let t = 0\n for (let i = 0; i < lst1.length; i++) {\n if (lst1[i] % 2 == 0) { t++ }\n }\n for (let i = 0; i < lst2.length; i++) {\n if (lst2[i] % 2 == 0) { t++ }\n }\n if (k >= t) { return 'YES' }\n return 'NO'\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "Exchange"} {"task_id": "JavaScript/111", "prompt": "/*Given a string representing a space separated lowercase letters, return a dictionary\n of the letter with the most repetition and containing the corresponding count.\n If several letters have the same occurrence, return all of them.\n \n Example:\n histogram('a b c') == {'a': 1, 'b': 1, 'c': 1}\n histogram('a b b a') == {'a': 2, 'b': 2}\n histogram('a b c a b') == {'a': 2, 'b': 2}\n histogram('b b b b a') == {'b': 4}\n histogram('') == {}\n\n */\nconst histogram = (test) => {\n", "canonical_solution": " let d = {}\n let t = test.split(/\\s/)\n if (test == '') { t = [] }\n for (m in t) {\n if (t[m] in d) {\n d[t[m]]++\n }\n else {\n d[t[m]] = 1\n }\n }\n s = Object.keys(d).sort(function (a, b) { return - d[a] + d[b]; });\n if (s.length == 0) { return {} }\n let g = d[s[0]]\n let l = {}\n for (let ss=0; ss {\n console.assert(\n JSON.stringify(histogram('a b b a')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c a b')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c d g')) ===\n JSON.stringify({ a: 1, b: 1, c: 1, d: 1, g: 1 })\n )\n console.assert(\n JSON.stringify(histogram('r t g')) === JSON.stringify({ r: 1, t: 1, g: 1 })\n )\n console.assert(\n JSON.stringify(histogram('b b b b a')) === JSON.stringify({ b: 4 })\n )\n console.assert(\n JSON.stringify(histogram('r t g')) === JSON.stringify({ r: 1, t: 1, g: 1 })\n )\n console.assert(JSON.stringify(histogram('')) === JSON.stringify({}))\n console.assert(JSON.stringify(histogram('a')) === JSON.stringify({ a: 1 }))\n}\n\ntestHistogram()\n", "declaration": "\nconst histogram = (test) => {\n", "example_test": "const testHistogram = () => {\n console.assert(\n JSON.stringify(histogram('a b b a')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c a b')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c d g')) ===\n JSON.stringify({ a: 1, b: 1, c: 1, d: 1, g: 1 })\n )\n console.assert(\n JSON.stringify(histogram('a b c')) === JSON.stringify({ a: 1, b: 1, c: 1 })\n )\n console.assert(\n JSON.stringify(histogram('b b b b a')) === JSON.stringify({ b: 4 })\n )\n console.assert(JSON.stringify(histogram('')) === JSON.stringify({}))\n}\ntestHistogram()\n", "buggy_solution": " let d = {}\n let t = test.split(/\\s/)\n if (test == '') { t = [] }\n for (m in t) {\n if (t[m] in d) {\n d[t[m]]++\n }\n else {\n d[t[m]] = 1\n }\n }\n s = Object.keys(d).sort(function (a, b) { return - d[a] + d[b]; });\n if (s.length == 0) { return {} }\n let g = d[s[0]]\n let l = {}\n for (let ss=1; ss {\n", "canonical_solution": " let t = ''\n for (let i = 0; i < s.length; i++) {\n let y = 1\n for (let j = 0; j < c.length; j++) {\n if (s[i] == c[j]) {\n y = 0\n }\n }\n if (y == 1) {\n t += s[i]\n }\n }\n let z = 1\n for (let i = 0; i < t.length; i++) {\n if (t[i] != t[t.length - i - 1]) {\n z = 0\n }\n }\n if (z == 0) {\n return (z, false)\n }\n return (z, true)\n}\n\n", "test": "const testReverseDelete = () => {\n console.assert(JSON.stringify(reverseDelete('abcde', 'ae'))) ===\n JSON.stringify(['bcd', false])\n console.assert(JSON.stringify(reverseDelete('abcdef', 'b'))) ===\n JSON.stringify(['acdef', false])\n console.assert(JSON.stringify(reverseDelete('abcdedcba', 'ab'))) ===\n JSON.stringify(['cdedc', true])\n console.assert(JSON.stringify(reverseDelete('dwik', 'w'))) ===\n JSON.stringify(['dik', false])\n console.assert(JSON.stringify(reverseDelete('a', 'a'))) ===\n JSON.stringify(['', true])\n console.assert(JSON.stringify(reverseDelete('abcdedcba', ''))) ===\n JSON.stringify(['abcdedcba', true])\n console.assert(JSON.stringify(reverseDelete('abcdedcba', 'v'))) ===\n JSON.stringify(['abcdedcba', true])\n console.assert(JSON.stringify(reverseDelete('vabba', 'v'))) ===\n JSON.stringify(['abba', true])\n console.assert(JSON.stringify(reverseDelete('mamma', 'mia'))) ===\n JSON.stringify(['', true])\n}\n\ntestReverseDelete()\n", "declaration": "\nconst reverseDelete = (s, c) => {\n", "example_test": "const testReverseDelete = () => {\n console.assert(JSON.stringify(reverseDelete('abcde', 'ae'))) ===\n JSON.stringify(['bcd', false])\n console.assert(JSON.stringify(reverseDelete('abcdef', 'b'))) ===\n JSON.stringify(['acdef', false])\n console.assert(JSON.stringify(reverseDelete('abcdedcba', 'ab'))) ===\n JSON.stringify(['cdedc', true])\n}\ntestReverseDelete()\n", "buggy_solution": " let t = ''\n for (let i = 0; i < s.length; i++) {\n let y = 1\n for (let j = 0; j < c.length; j++) {\n if (s[i] == c[j]) {\n y = 0\n }\n }\n if (y == 1) {\n t += s[i]\n }\n }\n let z = 1\n for (let i = 0; i < t.length; i++) {\n if (t[i] != t[t.length - i - 1]) {\n z = 0\n }\n }\n if (z == 0) {\n return (z, true)\n }\n return (z, false)\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "ReverseDelete"} +{"task_id": "JavaScript/112", "prompt": "/*Task\n We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c\n then check if the result string is palindrome.\n A string is called palindrome if it reads the same backward as forward.\n You should return a tuple containing the result string and true/false for the check.\n Example\n For s = \"abcde\", c = \"ae\", the result should be ('bcd',false)\n For s = \"abcdef\", c = \"b\" the result should be ('acdef',false)\n For s = \"abcdedcba\", c = \"ab\", the result should be ('cdedc',true)\n */\nconst reverseDelete = (s, c) => {\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 = 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/116", "prompt": "/*\n In this Kata, you have to sort an array of non-negative integers according to\n number of ones in their binary representation in ascending order.\n For similar number of ones, sort based on decimal value.\n\n It must be implemented like this:\n >>> sortArray([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]\n >>> sortArray([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]\n >>> sortArray([1, 0, 2, 3, 4]) [0, 1, 2, 3, 4]\n */\nconst sortArray = (arr) => {\n", "canonical_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n let w1 = p[ind].toString(2)\n let f1 = 0\n for (let u = 0; u < w1.length; u++) {\n if (w1[u] == '1') { f1++ }\n }\n let w2 = p[k].toString(2)\n let f2 = 0\n for (let u = 0; u < w2.length; u++) {\n if (w2[u] == '1') { f2++ }\n }\n if (f2 < f1 || (f1 == f2 && p[k] < p[ind])) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "test": "const testSortArray = () => {\n console.assert(\n JSON.stringify(sortArray([1, 5, 2, 3, 4])) ===\n JSON.stringify([1, 2, 4, 3, 5])\n )\n\n console.assert(\n JSON.stringify(sortArray([-2, -3, -4, -5, -6])) ===\n JSON.stringify([-4, -2, -6, -5, -3])\n )\n console.assert(\n JSON.stringify(sortArray([1, 0, 2, 3, 4])) ===\n JSON.stringify([0, 1, 2, 4, 3])\n )\n console.assert(JSON.stringify(sortArray([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(sortArray([2, 5, 77, 4, 5, 3, 5, 7, 2, 3, 4])) ===\n JSON.stringify([2, 2, 4, 4, 3, 3, 5, 5, 5, 7, 77])\n )\n console.assert(\n JSON.stringify(sortArray([3, 6, 44, 12, 32, 5])) ===\n JSON.stringify([32, 3, 5, 6, 12, 44])\n )\n console.assert(\n JSON.stringify(sortArray([2, 4, 8, 16, 32])) ===\n JSON.stringify([2, 4, 8, 16, 32])\n )\n console.assert(\n JSON.stringify(sortArray([2, 4, 8, 16, 32])) ===\n JSON.stringify([2, 4, 8, 16, 32])\n )\n}\n\ntestSortArray()\n", "declaration": "\nconst sortArray = (arr) => {\n", "example_test": "const testSortArray = () => {\n console.assert(\n JSON.stringify(sortArray([1, 5, 2, 3, 4])) ===\n JSON.stringify([1, 2, 4, 3, 5])\n )\n console.assert(\n JSON.stringify(sortArray([-2, -3, -4, -5, -6])) ===\n JSON.stringify([-4, -2, -6, -5, -3])\n )\n console.assert(\n JSON.stringify(sortArray([1, 0, 2, 3, 4])) ===\n JSON.stringify([0, 1, 2, 4, 3])\n )\n}\ntestSortArray()\n", "buggy_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n let w1 = p[ind].toString(2)\n let f1 = 0\n for (let u = 0; u < w1.length; u++) {\n if (w1[u] == '1') { f1++ }\n }\n let w2 = p[ind].toString(2)\n let f2 = 0\n for (let u = 0; u < w2.length; u++) {\n if (w2[u] == '1') { f2++ }\n }\n if (f2 < f1 || (f1 == f2 && p[k] < p[ind])) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return arr\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "SortArray"} {"task_id": "JavaScript/117", "prompt": "/*Given a string s and a natural number n, you have been tasked to implement \n a function that returns a list of all words from string s that contain exactly \n n consonants, in order these words appear in the string s.\n If the string s is empty then the function should return an empty list.\n Note: you may assume the input string contains only letters and spaces.\n Examples:\n selectWords(\"Mary had a little lamb\", 4) ==> [\"little\"]\n selectWords(\"Mary had a little lamb\", 3) ==> [\"Mary\")\n selectWords(\"simple white space\", 2) ==> []\n selectWords(\"Hello world\", 4) ==> [\"world\"]\n selectWords(\"Uncle sam\", 3) ==> [\"Uncle\"]\n */\nconst selectWords = (s, n) => {\n", "canonical_solution": " let t = s.split(/\\s/)\n if (s == '') { return [] }\n let k = []\n for (let i = 0; i < t.length; i++) {\n let l = 0\n for (let j = 0; j < t[i].length; j++) {\n if (t[i][j] != 'a' && t[i][j] != 'e' && t[i][j] != 'i' && t[i][j] != 'o' && t[i][j] != 'u' && t[i][j] != 'A' &&\n t[i][j] != 'U' && t[i][j] != 'O' && t[i][j] != 'I' && t[i][j] != 'E') {\n l++\n }\n }\n if (l == n) { k.push(t[i]) }\n }\n return k\n}\n\n", "test": "const testSelectWords = () => {\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 4)) ===\n JSON.stringify(['little'])\n )\n console.assert(\n JSON.stringify(selectWords('simple white space', 2)) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(selectWords('Hello world', 4)) === JSON.stringify(['world'])\n )\n console.assert(\n JSON.stringify(selectWords('Uncle sam', 3)) === JSON.stringify(['Uncle'])\n )\n\n console.assert(\n JSON.stringify(selectWords('a b c d e f', 1)) ===\n JSON.stringify(['b', 'c', 'd', 'f'])\n )\n\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 3)) ===\n JSON.stringify(['Mary', 'lamb'])\n )\n console.assert(JSON.stringify(selectWords('', 4)) === JSON.stringify([]))\n}\n\ntestSelectWords()\n", "declaration": "\nconst selectWords = (s, n) => {\n", "example_test": "const testSelectWords = () => {\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 4)) ===\n JSON.stringify(['little'])\n )\n console.assert(\n JSON.stringify(selectWords('simple white space', 2)) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(selectWords('Hello world', 4)) === JSON.stringify(['world'])\n )\n console.assert(\n JSON.stringify(selectWords('Uncle sam', 3)) === JSON.stringify(['Uncle'])\n )\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 3)) ===\n JSON.stringify(['Mary', 'lamb'])\n )\n}\ntestSelectWords()\n", "buggy_solution": " let t = s.split(/\\s/)\n if (s == '') { return [] }\n let k = []\n for (let i = 0; i < t.length; i++) {\n let l = 0\n for (let j = 0; j < t[i].length; j++) {\n if (t[i][j] != 'a' || t[i][j] != 'e' || t[i][j] != 'i' || t[i][j] != 'o' || t[i][j] != 'u' || t[i][j] != 'A' ||\n t[i][j] != 'U' || t[i][j] != 'O' || t[i][j] != 'I' || t[i][j] != 'E') {\n l++\n }\n }\n if (l == n) { k.push(t[i]) }\n }\n return k\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "SelectWords"} {"task_id": "JavaScript/118", "prompt": "/*You are given a word. Your task is to find the closest vowel that stands between \n two consonants from the right side of the word (case sensitive).\n \n Vowels in the beginning and ending doesn't count. Return empty string if you didn't\n find any vowel met the above condition. \n\n You may assume that the given string contains English letter only.\n\n Example:\n getClosestVowel(\"yogurt\") ==> \"u\"\n getClosestVowel(\"FULL\") ==> \"U\"\n getClosestVowel(\"quick\") ==> \"\"\n getClosestVowel(\"ab\") ==> \"\"\n */\nconst getClosestVowel = (word) => {\n", "canonical_solution": " for (let i = word.length - 2; i > 0; i--) {\n if (\n !(word[i] != 'a' && word[i] != 'e' && word[i] != 'i' && word[i] != 'o' && word[i] != 'u' && word[i] != 'A' &&\n word[i] != 'U' && word[i] != 'O' && word[i] != 'I' && word[i] != 'E')\n &&\n (word[i + 1] != 'a' && word[i + 1] != 'e' && word[i + 1] != 'i' && word[i + 1] != 'o' && word[i + 1] != 'u' && word[i + 1] != 'A' &&\n word[i + 1] != 'U' && word[i + 1] != 'O' && word[i + 1] != 'I' && word[i + 1] != 'E')\n &&\n (word[i - 1] != 'a' && word[i - 1] != 'e' && word[i - 1] != 'i' && word[i - 1] != 'o' && word[i - 1] != 'u' && word[i - 1] != 'A' &&\n word[i - 1] != 'U' && word[i - 1] != 'O' && word[i - 1] != 'I' && word[i - 1] != 'E')\n ) {\n return word[i]\n }\n }\n return ''\n}\n\n", "test": "const testGetClosestVowel = () => {\n console.assert(getClosestVowel('yogurt') === 'u')\n console.assert(getClosestVowel('full') === 'u')\n console.assert(getClosestVowel('easy') === '')\n console.assert(getClosestVowel('eAsy') === '')\n console.assert(getClosestVowel('ali') === '')\n console.assert(getClosestVowel('bad') === 'a')\n console.assert(getClosestVowel('most') === 'o')\n console.assert(getClosestVowel('ab') === '')\n console.assert(getClosestVowel('ba') === '')\n console.assert(getClosestVowel('quick') === '')\n console.assert(getClosestVowel('anime') === 'i')\n console.assert(getClosestVowel('Asia') === '')\n console.assert(getClosestVowel('Above') === 'o')\n}\n\ntestGetClosestVowel()\n", "declaration": "\nconst getClosestVowel = (word) => {\n", "example_test": "const testGetClosestVowel = () => {\n console.assert(getClosestVowel('yogurt') === 'u')\n console.assert(getClosestVowel('FULL') === 'U')\n console.assert(getClosestVowel('ab') === '')\n console.assert(getClosestVowel('quick') === '')\n}\ntestGetClosestVowel()\n", "buggy_solution": " for (let i = word.length - 2; i > 0; i--) {\n if (\n (word[i] != 'a' && word[i] != 'e' && word[i] != 'i' && word[i] != 'o' && word[i] != 'u' && word[i] != 'A' &&\n word[i] != 'U' && word[i] != 'O' && word[i] != 'I' && word[i] != 'E')\n &&\n (word[i + 1] != 'a' && word[i + 1] != 'e' && word[i + 1] != 'i' && word[i + 1] != 'o' && word[i + 1] != 'u' && word[i + 1] != 'A' &&\n word[i + 1] != 'U' && word[i + 1] != 'O' && word[i + 1] != 'I' && word[i + 1] != 'E')\n &&\n (word[i - 1] != 'a' && word[i - 1] != 'e' && word[i - 1] != 'i' && word[i - 1] != 'o' && word[i - 1] != 'u' && word[i - 1] != 'A' &&\n word[i - 1] != 'U' && word[i - 1] != 'O' && word[i - 1] != 'I' && word[i - 1] != 'E')\n ) {\n return word[i]\n }\n }\n return ' '\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "GetClosestVowel"} -{"task_id": "JavaScript/119", "prompt": "/* You are given a list of two strings, both strings consist of open\n parentheses '(' or close parentheses ')' only.\n Your job is to check if it is possible to concatenate the two strings in\n some order, that the resulting string will be good.\n A string S is considered to be good if and only if all parentheses in S\n are balanced. For example: the string '(())()' is good, while the string\n '())' is not.\n Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.\n Examples:\n matchParens(['()(', ')']) == 'Yes'\n matchParens([')', ')']) == 'No'\n */\nconst matchParens = (lst) => {\n", "canonical_solution": " let w1 = lst[0] + lst[1]\n let y = 0\n let u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'Yes' }\n w1 = lst[1] + lst[0]\n y = 0\n u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'Yes' }\n return 'No'\n}\n\n", "test": "const testMatchParens = () => {\n console.assert(matchParens(['()(', ')']) === 'Yes')\n console.assert(matchParens([')', ')']) === 'No')\n console.assert(matchParens(['(()(())', '())())']) === 'No')\n console.assert(matchParens([')())', '(()()(']) === 'Yes')\n console.assert(matchParens(['(())))', '(()())((']) === 'Yes')\n console.assert(matchParens(['()', '())']) === 'No')\n console.assert(matchParens(['(()(', '()))()']) === 'Yes')\n console.assert(matchParens(['((((', '((())']) === 'No')\n console.assert(matchParens([')(()', '(()(']) === 'No')\n console.assert(matchParens([')(', ')(']) === 'No')\n console.assert(matchParens(['(', ')']) === 'Yes')\n console.assert(matchParens([')', '(']) === 'Yes')\n}\n", "declaration": "\nconst matchParens = (lst) => {\n", "example_test": "const testMatchParens = () => {\n console.assert(matchParens(['()(', ')']) === 'Yes')\n console.assert(matchParens([')', ')']) === 'No')\n}\ntestMatchParens()\n", "buggy_solution": " let w1 = lst[0] + lst[1]\n let y = 0\n let u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'Yes' }\n w1 = lst[1] + lst[0]\n y = 0\n u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'yes' }\n return 'no'\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "MatchParens"} +{"task_id": "JavaScript/119", "prompt": "/* You are given a list of two strings, both strings consist of open\n parentheses '(' or close parentheses ')' only.\n Your job is to check if it is possible to concatenate the two strings in\n some order, that the resulting string will be good.\n A string S is considered to be good if and only if all parentheses in S\n are balanced. For example: the string '(())()' is good, while the string\n '())' is not.\n Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.\n Examples:\n matchParens(['()(', ')']) == 'Yes'\n matchParens([')', ')']) == 'No'\n */\nconst matchParens = (lst) => {\n", "canonical_solution": " let w1 = lst[0] + lst[1]\n let y = 0\n let u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'Yes' }\n w1 = lst[1] + lst[0]\n y = 0\n u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'Yes' }\n return 'No'\n}\n\n", "test": "const testMatchParens = () => {\n console.assert(matchParens(['()(', ')']) === 'Yes')\n console.assert(matchParens([')', ')']) === 'No')\n console.assert(matchParens(['(()(())', '())())']) === 'No')\n console.assert(matchParens([')())', '(()()(']) === 'Yes')\n console.assert(matchParens(['(())))', '(()())((']) === 'Yes')\n console.assert(matchParens(['()', '())']) === 'No')\n console.assert(matchParens(['(()(', '()))()']) === 'Yes')\n console.assert(matchParens(['((((', '((())']) === 'No')\n console.assert(matchParens([')(()', '(()(']) === 'No')\n console.assert(matchParens([')(', ')(']) === 'No')\n console.assert(matchParens(['(', ')']) === 'Yes')\n console.assert(matchParens([')', '(']) === 'Yes')\n}\n", "declaration": "\nconst matchParens = (lst) => {\n", "example_test": "const testMatchParens = () => {\n console.assert(matchParens(['()(', ')']) === 'Yes')\n console.assert(matchParens([')', ')']) === 'No')\n}\ntestMatchParens()\n", "buggy_solution": " let w1 = lst[0] + lst[1]\n let y = 0\n let u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'yes' }\n w1 = lst[1] + lst[0]\n y = 0\n u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'no' }\n return 'yes'\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "MatchParens"} {"task_id": "JavaScript/120", "prompt": "/*\n Given an array arr of integers and a positive integer k, return a sorted list \n of length k with the maximum k numbers in arr.\n\n Example 1:\n\n Input: arr = [-3, -4, 5], k = 3\n Output: [-4, -3, 5]\n\n Example 2:\n\n Input: arr = [4, -4, 4], k = 2\n Output: [4, 4]\n\n Example 3:\n\n Input: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1\n Output: [2]\n\n Note:\n 1. The length of the array will be in the range of [1, 1000].\n 2. The elements in the array will be in the range of [-1000, 1000].\n 3. 0 <= k <= len(arr)\n */\nconst maximum = (arr, k) => {\n", "canonical_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n if (k == 0) { return [] }\n return p.slice(-k)\n}\n\n", "test": "const testMaximum = () => {\n console.assert(\n JSON.stringify(maximum([-3, -4, 5], 3)) === JSON.stringify([-4, -3, 5])\n )\n console.assert(\n JSON.stringify(maximum([4, -4, 4], 2)) === JSON.stringify([4, 4])\n )\n console.assert(\n JSON.stringify(maximum([-3, 2, 1, 2, -1, -2, 1], 1)) === JSON.stringify([2])\n )\n console.assert(\n JSON.stringify(maximum([123, -123, 20, 0, 1, 2, -3], 3)) ===\n JSON.stringify([2, 20, 123])\n )\n console.assert(\n JSON.stringify(maximum([-123, 20, 0, 1, 2, -3], 4)) ===\n JSON.stringify([0, 1, 2, 20])\n )\n console.assert(\n JSON.stringify(maximum([5, 15, 0, 3, -13, -8, 0], 7)) ===\n JSON.stringify([-13, -8, 0, 0, 3, 5, 15])\n )\n console.assert(\n JSON.stringify(maximum([-1, 0, 2, 5, 3, -10], 2)) === JSON.stringify([3, 5])\n )\n console.assert(\n JSON.stringify(maximum([1, 0, 5, -7], 1)) === JSON.stringify([5])\n )\n console.assert(JSON.stringify(maximum([4, -4], 2)) === JSON.stringify([-4, 4]))\n console.assert(\n JSON.stringify(maximum([-10, 10], 2)) === JSON.stringify([-10, 10])\n )\n console.assert(\n JSON.stringify(maximum([1, 2, 3, -23, 243, -400, 0], 0)) ===\n JSON.stringify([])\n )\n}\n\ntestMaximum()\n", "declaration": "\nconst maximum = (arr, k) => {\n", "example_test": "const testMaximum = () => {\n console.assert(\n JSON.stringify(maximum([-3, -4, 5], 3)) === JSON.stringify([-4, -3, 5])\n )\n console.assert(\n JSON.stringify(maximum([4, -4, 4], 2)) === JSON.stringify([4, 4])\n )\n console.assert(\n JSON.stringify(maximum([-3, 2, 1, 2, -1, -2, 1], 1)) === JSON.stringify([2])\n )\n}\ntestMaximum()\n", "buggy_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n p[j] = p[ind]\n }\n }\n if (k == 0) { return [] }\n return p.slice(-k)\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Maximum"} {"task_id": "JavaScript/121", "prompt": "/*Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions.\n \n\n Examples\n solution([5, 8, 7, 1]) ==> 12\n solution([3, 3, 3, 3, 3]) ==> 9\n solution([30, 13, 24, 321]) ==>0\n */\nconst solution = (lst) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < lst.length; i += 2) {\n if (lst[i] % 2 == 1) {\n p += lst[i]\n }\n }\n return p\n}\n\n", "test": "const testSolution = () => {\n console.assert(solution([5, 8, 7, 1]) === 12)\n console.assert(solution([3, 3, 3, 3, 3]) === 9)\n console.assert(solution([30, 13, 24, 321]) === 0)\n console.assert(solution([5, 9]) === 5)\n console.assert(solution([2, 4, 8]) === 0)\n console.assert(solution([30, 13, 23, 32]) === 23)\n console.assert(solution([3, 13, 2, 9]) === 3)\n}\n\ntestSolution()\n", "declaration": "\nconst solution = (lst) => {\n", "example_test": "const testSolution = () => {\n console.assert(solution([5, 8, 7, 1]) === 12)\n console.assert(solution([3, 3, 3, 3, 3]) === 9)\n console.assert(solution([30, 13, 24, 321]) === 0)\n}\ntestSolution()\n", "buggy_solution": " let p = 1\n for (let i = 0; i < lst.length; i += 2) {\n if (lst[i] % 2 == 1) {\n p += lst[i]\n }\n }\n return p\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Solution"} {"task_id": "JavaScript/122", "prompt": "/*\n Given a non-empty array of integers arr and an integer k, return\n the sum of the elements with at most two digits from the first k elements of arr.\n\n Example:\n\n Input: arr = [111,21,3,4000,5,6,7,8,9], k = 4\n Output: 24 # sum of 21 + 3\n\n Constraints:\n 1. 1 <= len(arr) <= 100\n 2. 1 <= k <= len(arr)\n */\nconst addElements = (arr, k) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < k; i++) {\n if (arr[i] < 100 && arr[i] > -100) { p += arr[i] }\n }\n return p\n}\n\n", "test": "const testAddElements = () => {\n console.assert(addElements([1, -2, -3, 41, 57, 76, 87, 88, 99], 3) === -4)\n console.assert(addElements([111, 121, 3, 4000, 5, 6], 2) === 0)\n console.assert(addElements([11, 21, 3, 90, 5, 6, 7, 8, 9], 4) === 125)\n console.assert(addElements([111, 21, 3, 4000, 5, 6, 7, 8, 9], 4) === 24)\n console.assert(addElements([1], 1) === 1)\n}\n\ntestAddElements()\n", "declaration": "\nconst addElements = (arr, k) => {\n", "example_test": "const testAddElements = () => {\n console.assert(addElements([111, 21, 3, 4000, 5, 6, 7, 8, 9], 4) === 24)\n}\ntestAddElements()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] < 100 && arr[i] > -100) { p += arr[i] }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "AddElements"} @@ -125,7 +125,7 @@ {"task_id": "JavaScript/124", "prompt": "/*You have to write a function which validates a given date string and\n returns true if the date is valid otherwise false.\n The date is valid if all of the following rules are satisfied:\n 1. The date string is not empty.\n 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n 3. The months should not be less than 1 or higher than 12.\n 4. The date should be in the format: mm-dd-yyyy\n\n for example: \n validDate('03-11-2000') => true\n\n validDate('15-01-2012') => false\n\n validDate('04-0-2040') => false\n\n validDate('06-04-2020') => true\n\n validDate('06/04/2020') => false\n */\nconst validDate = (date) => {\n", "canonical_solution": " let t = date.split(/-/)\n if (t.length != 3) { return false }\n if (t[0] < 1 || t[0] > 12 || t[1] < 1) { return false }\n if (t[0] == 2 && t[1] > 29) { return false }\n if ((t[0] == 1 || t[0] == 3 || t[0] == 5 || t[0] == 7 || t[0] == 8 || t[0] == 10 || t[0] == 12) && t[1] > 31) { return false }\n if ((t[0] == 4 || t[0] == 6 || t[0] == 9 || t[0] == 11) && t[1] > 30) { return false }\n return true\n}\n\n", "test": "const testValidDate = () => {\n console.assert(validDate('03-11-2000') === true)\n console.assert(validDate('15-01-2012') === false)\n console.assert(validDate('04-0-2040') === false)\n console.assert(validDate('06-04-2020') === true)\n console.assert(validDate('01-01-2007') === true)\n console.assert(validDate('03-32-2011') === false)\n console.assert(validDate('') === false)\n console.assert(validDate('04-31-3000') === false)\n console.assert(validDate('06-06-2005') === true)\n console.assert(validDate('21-31-2000') === false)\n console.assert(validDate('04-12-2003') === true)\n console.assert(validDate('04122003') === false)\n console.assert(validDate('20030412') === false)\n console.assert(validDate('2003-04') === false)\n console.assert(validDate('2003-04-12') === false)\n console.assert(validDate('04-2003') === false)\n}\n\ntestValidDate()\n", "declaration": "\nconst validDate = (date) => {\n", "example_test": "const testValidDate = () => {\n console.assert(validDate('03-11-2000') === true)\n console.assert(validDate('15-01-2012') === false)\n console.assert(validDate('04-0-2040') === false)\n console.assert(validDate('06-04-2020') === true)\n console.assert(validDate('06/04/2020') === false)\n}\ntestValidDate()\n", "buggy_solution": " let t = date.split(/-/)\n if (t.length != 3) { return false }\n if (t[1] < 1 || t[1] > 12 || t[0] < 1) { return false }\n if (t[1] == 2 && t[0] > 29) { return false }\n if ((t[1] == 1 || t[1] == 3 || t[1] == 5 || t[1] == 7 || t[1] == 8 || t[1] == 10 || t[1] == 12) && t[0] > 31) { return false }\n if ((t[1] == 4 || t[1] == 6 || t[1] == 9 || t[1] == 11) && t[0] > 30) { return false }\n return true\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "ValidDate"} {"task_id": "JavaScript/125", "prompt": "/* Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you\n should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the\n alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25\n Examples\n splitWords(\"Hello world!\") \u279e [\"Hello\", \"world!\"]\n splitWords(\"Hello,world!\") \u279e [\"Hello\", \"world!\"]\n splitWords(\"abcdef\") == 3\n */\nconst splitWords = (txt) => {\n", "canonical_solution": " let t = txt.split(/\\s/)\n if (t.length > 1) {\n return t\n } else {\n t = txt.split(/,/)\n if (t.length > 1) {\n return t\n } else {\n let p = 0\n for (let i = 0; i < txt.length; i++) {\n let m = txt[i].charCodeAt()\n if (m >= 97 && m <= 122 && m % 2 == 0) {\n p++\n }\n }\n return p\n }\n }\n}\n\n", "test": "const testSplitWords = () => {\n console.assert(\n JSON.stringify(splitWords('Hello world!')) ===\n JSON.stringify(['Hello', 'world!'])\n )\n console.assert(\n JSON.stringify(splitWords('Hello,world!')) ===\n JSON.stringify(['Hello', 'world!'])\n )\n console.assert(\n JSON.stringify(splitWords('Hello world,!')) ===\n JSON.stringify(['Hello', 'world,!'])\n )\n console.assert(\n JSON.stringify(splitWords('Hello,Hello,world !')) ===\n JSON.stringify(['Hello,Hello,world', '!'])\n )\n console.assert(JSON.stringify(splitWords('abcdef')) === JSON.stringify(3))\n console.assert(JSON.stringify(splitWords('aaabb')) === JSON.stringify(2))\n console.assert(JSON.stringify(splitWords('aaaBb')) === JSON.stringify(1))\n console.assert(JSON.stringify(splitWords('')) === JSON.stringify(0))\n}\n\ntestSplitWords()\n", "declaration": "\nconst splitWords = (txt) => {\n", "example_test": "const testSplitWords = () => {\n console.assert(\n JSON.stringify(splitWords('Hello world!')) ===\n JSON.stringify(['Hello', 'world!'])\n )\n console.assert(\n JSON.stringify(splitWords('Hello,world!')) ===\n JSON.stringify(['Hello', 'world!'])\n )\n console.assert(JSON.stringify(splitWords('abcdef')) === JSON.stringify(3))\n}\ntestSplitWords()\n", "buggy_solution": " let t = txt.split(/,/)\n if (t.length > 1) {\n return t\n } else {\n t = txt.split(/\\s/)\n if (t.length > 1) {\n return t\n } else {\n let p = 0\n for (let i = 0; i < txt.length; i++) {\n let m = txt[i].charCodeAt()\n if (m >= 97 && m <= 122 && m % 2 == 0) {\n p++\n }\n }\n return p\n }\n }\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "SplitWords"} {"task_id": "JavaScript/126", "prompt": "/* Given a list of numbers, return whether or not they are sorted\n in ascending order. If list has more than 1 duplicate of the same\n number, return false. Assume no negative numbers and only integers.\n Examples\n isSorted([5]) \u279e true\n isSorted([1, 2, 3, 4, 5]) \u279e true\n isSorted([1, 3, 2, 4, 5]) \u279e false\n isSorted([1, 2, 3, 4, 5, 6]) \u279e true\n isSorted([1, 2, 3, 4, 5, 6, 7]) \u279e true\n isSorted([1, 3, 2, 4, 5, 6, 7]) \u279e false\n isSorted([1, 2, 2, 3, 3, 4]) \u279e true\n isSorted([1, 2, 2, 2, 3, 4]) \u279e false\n */\nconst isSorted = (lst) => {\n", "canonical_solution": " if (lst.length == 0) { return true }\n let dup = 1\n let pre = lst[0]\n for (let i = 1; i < lst.length; i++) {\n if (lst[i] < pre) { return false }\n if (lst[i] == pre) {\n dup += 1;\n if (dup == 3) { return false }\n } else {\n pre = lst[i]\n dup = 1\n }\n }\n return true\n}\n\n", "test": "const testIsSorted = () => {\n console.assert(isSorted([5]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5]) === false)\n console.assert(isSorted([1, 2, 3, 4, 5, 6]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5, 6, 7]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5, 6, 7]) === false)\n console.assert(isSorted([]) === true)\n console.assert(isSorted([1]) === true)\n console.assert(isSorted([3, 2, 1]) === false)\n console.assert(isSorted([1, 2, 2, 2, 3, 4]) === false)\n console.assert(isSorted([1, 2, 3, 3, 3, 4]) === false)\n console.assert(isSorted([1, 2, 2, 3, 3, 4]) === true)\n console.assert(isSorted([1, 2, 3, 4]) === true)\n}\n\ntestIsSorted()\n", "declaration": "\nconst isSorted = (lst) => {\n", "example_test": "const testIsSorted = () => {\n console.assert(isSorted([5]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5]) === false)\n console.assert(isSorted([1, 2, 3, 4, 5, 6]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5, 6, 7]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5, 6, 7]) === false)\n console.assert(isSorted([1, 2, 2, 2, 3, 4]) === false)\n console.assert(isSorted([1, 2, 2, 3, 3, 4]) === true)\n}\ntestIsSorted()\n", "buggy_solution": " if (lst.length == 0) { return true }\n let dup = 1\n let pre = lst[0]\n for (let i = 1; i < lst.length; i++) {\n if (lst[i] < pre) { return false }\n if (lst[i] == pre) {\n dup += 1;\n if (dup == 3) { return false }\n } else {\n pre = lst[i]\n }\n }\n return true\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "IsSorted"} -{"task_id": "JavaScript/127", "prompt": "/*You are given two intervals,\n where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\n The given intervals are closed which means that the interval (start, end)\n includes both start and end.\n For each given interval, it is assumed that its start is less or equal its end.\n Your task is to determine whether the length of intersection of these two \n intervals is a prime number.\n Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\n which its length is 1, which not a prime number.\n If the length of the intersection is a prime number, return \"YES\",\n otherwise, return \"NO\".\n If the two intervals don't intersect, return \"NO\".\n\n\n [input/output] samples:\n intersection((1, 2), (2, 3)) ==> \"NO\"\n intersection((-1, 1), (0, 4)) ==> \"NO\"\n intersection((-3, -1), (-5, 5)) ==> \"YES\"\n */\nconst intersection = (interval1, interval2) => {\n", "canonical_solution": " let lo = interval1[0]\n if (interval2[0] > lo) { lo = interval2[0] }\n let hi = interval1[1]\n if (interval2[1] < hi) { hi = interval2[1] }\n let len = 0\n if (hi > lo) { len = hi - lo }\n if (len == 1 || len == 0) { return 'NO' }\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { return 'NO' }\n }\n return 'YES'\n}\n\n", "test": "const testIntersection = () => {\n console.assert(intersection([1, 2], [2, 3]) === 'NO')\n console.assert(intersection([-1, 1], [0, 4]) === 'NO')\n console.assert(intersection([-3, -1], [-5, 5]) === 'YES')\n console.assert(intersection([-2, 2], [-4, 0]) === 'YES')\n console.assert(intersection([-11, 2], [-1, -1]) === 'NO')\n console.assert(intersection([1, 2], [3, 5]) === 'NO')\n console.assert(intersection([1, 2], [1, 2]) === 'NO')\n console.assert(intersection([-2, -2], [-3, -2]) === 'NO')\n}\n\ntestIntersection()\n", "declaration": "\nconst intersection = (interval1, interval2) => {\n", "example_test": "const testIntersection = () => {\n console.assert(intersection([1, 2], [2, 3]) === 'NO')\n console.assert(intersection([-1, 1], [0, 4]) === 'NO')\n console.assert(intersection([-3, -1], [-5, 5]) === 'YES')\n}\ntestIntersection()\n", "buggy_solution": " let lo = interval1[0]\n if (interval2[0] > lo) { lo = interval2[0] }\n let hi = interval1[1]\n if (interval2[1] < hi) { hi = interval2[1] }\n let len = 0\n if (hi > lo) { len = hi - lo }\n if (len == 1 || len == 0) { return 'NO' }\n return 'YES'\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "Intersection"} +{"task_id": "JavaScript/127", "prompt": "/*You are given two intervals,\n where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\n The given intervals are closed which means that the interval (start, end)\n includes both start and end.\n For each given interval, it is assumed that its start is less or equal its end.\n Your task is to determine whether the length of intersection of these two \n intervals is a prime number.\n Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\n which its length is 1, which not a prime number.\n If the length of the intersection is a prime number, return \"YES\",\n otherwise, return \"NO\".\n If the two intervals don't intersect, return \"NO\".\n\n\n [input/output] samples:\n intersection((1, 2), (2, 3)) ==> \"NO\"\n intersection((-1, 1), (0, 4)) ==> \"NO\"\n intersection((-3, -1), (-5, 5)) ==> \"YES\"\n */\nconst intersection = (interval1, interval2) => {\n", "canonical_solution": " let lo = interval1[0]\n if (interval2[0] > lo) { lo = interval2[0] }\n let hi = interval1[1]\n if (interval2[1] < hi) { hi = interval2[1] }\n let len = 0\n if (hi > lo) { len = hi - lo }\n if (len == 1 || len == 0) { return 'NO' }\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { return 'NO' }\n }\n return 'YES'\n}\n\n", "test": "const testIntersection = () => {\n console.assert(intersection([1, 2], [2, 3]) === 'NO')\n console.assert(intersection([-1, 1], [0, 4]) === 'NO')\n console.assert(intersection([-3, -1], [-5, 5]) === 'YES')\n console.assert(intersection([-2, 2], [-4, 0]) === 'YES')\n console.assert(intersection([-11, 2], [-1, -1]) === 'NO')\n console.assert(intersection([1, 2], [3, 5]) === 'NO')\n console.assert(intersection([1, 2], [1, 2]) === 'NO')\n console.assert(intersection([-2, -2], [-3, -2]) === 'NO')\n}\n\ntestIntersection()\n", "declaration": "\nconst intersection = (interval1, interval2) => {\n", "example_test": "const testIntersection = () => {\n console.assert(intersection([1, 2], [2, 3]) === 'NO')\n console.assert(intersection([-1, 1], [0, 4]) === 'NO')\n console.assert(intersection([-3, -1], [-5, 5]) === 'YES')\n}\ntestIntersection()\n", "buggy_solution": " let lo = interval1[0]\n if (interval2[0] > lo) { lo = interval2[0] }\n let hi = interval1[1]\n if (interval2[1] < hi) { hi = interval2[1] }\n let len = 0\n if (hi > lo) { len = hi }\n if (len == 1 || len == 0) { return 'NO' }\n return 'YES'\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "Intersection"} {"task_id": "JavaScript/128", "prompt": "/*\n You are given an array arr of integers and you need to return\n sum of magnitudes of integers multiplied by product of all signs\n of each number in the array, represented by 1, -1 or 0.\n Note: return null for empty arr.\n\n Example:\n >>> prodSigns([1, 2, 2, -4]) == -9\n >>> prodSigns([0, 1]) == 0\n >>> prodSigns([]) == null\n */\nconst prodSigns = (arr) => {\n", "canonical_solution": " if (arr.length == 0) { return null }\n let n = 1\n let s = 0\n for (let i = 0; i < arr.length; i++) {\n s += arr[i]\n if (arr[i] == 0) { return 0 }\n if (arr[i] < 0) { n = -n; s -= 2 * arr[i] }\n }\n return s * n\n}\n\n", "test": "const testProdSigns = () => {\n console.assert(prodSigns([1, 2, 2, -4]) === -9)\n console.assert(prodSigns([0, 1]) === 0)\n console.assert(prodSigns([1, 1, 1, 2, 3, -1, 1]) === -10)\n console.assert(prodSigns([]) === null)\n console.assert(prodSigns([2, 4, 1, 2, -1, -1, 9]) === 20)\n console.assert(prodSigns([-1, 1, -1, 1]) === 4)\n console.assert(prodSigns([-1, 1, 1, 1]) === -4)\n console.assert(prodSigns([-1, 1, 1, 0]) === 0)\n}\n\ntestProdSigns()\n", "declaration": "\nconst prodSigns = (arr) => {\n", "example_test": "const testProdSigns = () => {\n console.assert(prodSigns([1, 2, 2, -4]) === -9)\n console.assert(prodSigns([0, 1]) === 0)\n console.assert(prodSigns([]) === null)\n}\ntestProdSigns()\n", "buggy_solution": " if (arr.length == 0) { return null }\n let n = 1\n let s = 0\n for (let i = 0; i < arr.length; i++) {\n s += arr[i]\n if (arr[i] == 0) { return 0 }\n if (arr[i] < 0) { n = -n; s -= 2 * arr[i] }\n }\n return s * n * 2\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "ProdSigns"} {"task_id": "JavaScript/129", "prompt": "/*\n Given a grid with N rows and N columns (N >= 2) and a positive integer k, \n each cell of the grid contains a value. Every integer in the range [1, N * N]\n inclusive appears exactly once on the cells of the grid.\n\n You have to find the minimum path of length k in the grid. You can start\n from any cell, and in each step you can move to any of the neighbor cells,\n in other words, you can go to cells which share an edge with you current\n cell.\n Please note that a path of length k means visiting exactly k cells (not\n necessarily distinct).\n You CANNOT go off the grid.\n A path A (of length k) is considered less than a path B (of length k) if\n after making the ordered lists of the values on the cells that A and B go\n through (let's call them lst_A and lst_B), lst_A is lexicographically less\n than lst_B, in other words, there exist an integer index i (1 <= i <= k)\n such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\n lst_A[j] = lst_B[j].\n It is guaranteed that the answer is unique.\n Return an ordered list of the values on the cells that the minimum path go through.\n\n Examples:\n\n Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3\n Output: [1, 2, 1]\n\n Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1\n Output: [1]\n */\nconst minPath = (grid, k) => {\n", "canonical_solution": " let m = 0\n let n = 0\n for (let i = 0; i < grid.length; i++) {\n for (let j = 0; j < grid.length; j++) {\n if (grid[i][j] == 1) {\n m = i;\n n = j;\n break;\n }\n }\n }\n let min = grid.length * grid.length\n if (m > 0 && grid[m - 1][n] < min) { min = grid[m - 1][n] }\n if (n > 0 && grid[m][n - 1] < min) { min = grid[m][n - 1] }\n if (m < grid.length - 1 && grid[m + 1][n] < min) { min = grid[m + 1][n] }\n if (n < grid.length - 1 && grid[m][n + 1] < min) { min = grid[m][n + 1] }\n let p = []\n for (let i = 0; i < k; i++) {\n if (i % 2 == 0) { p.push(1) }\n else { p.push(min) }\n }\n return p\n}\n\n", "test": "const testMinPath = () => {\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9],\n ],\n 3\n )\n ) === JSON.stringify([1, 2, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [5, 9, 3],\n [4, 1, 6],\n [7, 8, 2],\n ],\n 1\n )\n ) === JSON.stringify([1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n ],\n 4\n )\n ) === JSON.stringify([1, 2, 1, 2])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [6, 4, 13, 10],\n [5, 7, 12, 1],\n [3, 16, 11, 15],\n [8, 14, 9, 2],\n ],\n 7\n )\n ) === JSON.stringify([1, 10, 1, 10, 1, 10, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [8, 14, 9, 2],\n [6, 4, 13, 15],\n [5, 7, 1, 12],\n [3, 10, 11, 16],\n ],\n 5\n )\n ) === JSON.stringify([1, 7, 1, 7, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [11, 8, 7, 2],\n [5, 16, 14, 4],\n [9, 3, 15, 6],\n [12, 13, 10, 1],\n ],\n 9\n )\n ) === JSON.stringify([1, 6, 1, 6, 1, 6, 1, 6, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [12, 13, 10, 1],\n [9, 3, 15, 6],\n [5, 16, 14, 4],\n [11, 8, 7, 2],\n ],\n 12\n )\n ) === JSON.stringify([1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [2, 7, 4],\n [3, 1, 5],\n [6, 8, 9],\n ],\n 8\n )\n ) === JSON.stringify([1, 3, 1, 3, 1, 3, 1, 3])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [6, 1, 5],\n [3, 8, 9],\n [2, 7, 4],\n ],\n 8\n )\n ) === JSON.stringify([1, 5, 1, 5, 1, 5, 1, 5])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2],\n [3, 4],\n ],\n 10\n )\n ) === JSON.stringify([1, 2, 1, 2, 1, 2, 1, 2, 1, 2])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 3],\n [4, 2],\n ],\n 10\n )\n ) === JSON.stringify([1, 3, 1, 3, 1, 3, 1, 3, 1, 3])\n )\n}\n\ntestMinPath()\n", "declaration": "\nconst minPath = (grid, k) => {\n", "example_test": "const testMinPath = () => {\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9],\n ],\n 3\n )\n ) === JSON.stringify([1, 2, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [5, 9, 3],\n [4, 1, 6],\n [7, 8, 2],\n ],\n 1\n )\n ) === JSON.stringify([1])\n )\n}\ntestMinPath()\n", "buggy_solution": " let m = 0\n let n = 0\n for (let i = 0; i < grid.length; i++) {\n for (let j = 0; j < grid.length; j++) {\n if (grid[i][j] == 1) {\n m = i;\n n = j;\n break;\n }\n }\n }\n let min = grid.length * grid.length\n if (m > 0 && grid[m - 1][n] < min) { min = grid[m][n] }\n if (n > 0 && grid[m][n - 1] < min) { min = grid[m][n] }\n if (m < grid.length - 1 && grid[m + 1][n] < min) { min = grid[m][n] }\n if (n < grid.length - 1 && grid[m][n + 1] < min) { min = grid[m][n] }\n let p = []\n for (let i = 0; i < k; i++) {\n if (i % 2 == 0) { p.push(1) }\n else { p.push(min) }\n }\n return p\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Minpath"} {"task_id": "JavaScript/130", "prompt": "/*Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in \n the last couple centuries. However, what people don't know is Tribonacci sequence.\n Tribonacci sequence is defined by the recurrence:\n tri(1) = 3\n tri(n) = 1 + n / 2, if n is even.\n tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\n For example:\n tri(2) = 1 + (2 / 2) = 2\n tri(4) = 3\n tri(3) = tri(2) + tri(1) + tri(4)\n = 2 + 3 + 3 = 8 \n You are given a non-negative integer number n, you have to a return a list of the \n first n + 1 numbers of the Tribonacci sequence.\n Examples:\n tri(3) = [1, 3, 2, 8]\n */\nconst tri = (n) => {\n", "canonical_solution": " if (n == 0) { return [1] }\n if (n == 1) { return [1, 3] }\n let p = [1, 3]\n for (let i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n p.push(1 + i / 2)\n }\n else {\n p.push(p[i - 2] + p[i - 1] + 1 + (i + 1) / 2)\n }\n }\n return p\n}\n\n", "test": "const testTri = () => {\n console.assert(JSON.stringify(tri(3)) === JSON.stringify([1, 3, 2.0, 8.0]))\n\n console.assert(\n JSON.stringify(tri(4)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0])\n )\n console.assert(\n JSON.stringify(tri(5)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0])\n )\n console.assert(\n JSON.stringify(tri(6)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0])\n )\n console.assert(\n JSON.stringify(tri(7)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0])\n )\n console.assert(\n JSON.stringify(tri(8)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0])\n )\n console.assert(\n JSON.stringify(tri(9)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0])\n )\n console.assert(\n JSON.stringify(tri(20)) ===\n JSON.stringify([\n 1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0, 6.0, 48.0, 7.0, 63.0,\n 8.0, 80.0, 9.0, 99.0, 10.0, 120.0, 11.0,\n ])\n )\n console.assert(JSON.stringify(tri(0)) === JSON.stringify([1]))\n console.assert(JSON.stringify(tri(1)) === JSON.stringify([1, 3]))\n}\n\ntestTri()\n", "declaration": "\nconst tri = (n) => {\n", "example_test": "const testTri = () => {\n console.assert(JSON.stringify(tri(3)) === JSON.stringify([1, 3, 2.0, 8.0]))\n}\ntestTri()\n", "buggy_solution": " if (n == 0) { return [1] }\n if (n == 1) { return [1, 3] }\n let p = [1, 3]\n for (let i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n p.push(1 + i / 2)\n }\n else {\n p.push(p[i - 2] + p[i - 1] + 1 + i + (i + 1) / 2)\n }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Tri"} @@ -134,11 +134,11 @@ {"task_id": "JavaScript/133", "prompt": "/*You are given a list of numbers.\n You need to return the sum of squared numbers in the given list,\n round each element in the list to the upper int(Ceiling) first.\n Examples:\n For lst = [1,2,3] the output should be 14\n For lst = [1,4,9] the output should be 98\n For lst = [1,3,5,7] the output should be 84\n For lst = [1.4,4.2,0] the output should be 29\n For lst = [-2.4,1,1] the output should be 6\n */\nconst sumSquares = (lst) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n let y = lst[i]\n if (y % 1 != 0) {\n if (y > 0) { y = y - y % 1 + 1 }\n else { y = -y; y = y - y % 1 }\n }\n p += y * y\n }\n return p\n}\n\n", "test": "const testSumSquares = () => {\n console.assert(sumSquares([1, 2, 3]) === 14)\n console.assert(sumSquares([1.0, 2, 3]) === 14)\n console.assert(sumSquares([1, 3, 5, 7]) === 84)\n console.assert(sumSquares([1.4, 4.2, 0]) === 29)\n console.assert(sumSquares([-2.4, 1, 1]) === 6)\n\n console.assert(sumSquares([100, 1, 15, 2]) === 10230)\n console.assert(sumSquares([10000, 10000]) === 200000000)\n console.assert(sumSquares([-1.4, 4.6, 6.3]) === 75)\n console.assert(sumSquares([-1.4, 17.9, 18.9, 19.9]) === 1086)\n\n console.assert(sumSquares([0]) === 0)\n console.assert(sumSquares([-1]) === 1)\n console.assert(sumSquares([-1, 1, 0]) === 2)\n}\n\ntestSumSquares()\n", "declaration": "\nconst sumSquares = (lst) => {\n", "example_test": "const testSumSquares = () => {\n console.assert(sumSquares([1, 2, 3]) === 14)\n console.assert(sumSquares([1, 4, 9]) === 98)\n console.assert(sumSquares([1, 3, 5, 7]) === 84)\n console.assert(sumSquares([1.4, 4.2, 0]) === 29)\n console.assert(sumSquares([-2.4, 1, 1]) === 6)\n}\ntestSumSquares()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n let y = lst[i]\n if (y % 1 != 0) {\n if (y > 0) { y = y - y % 1 + 1 }\n else { y = -y; y = y - y % 1 }\n }\n p += y * 2\n }\n return p\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "SumSquares"} {"task_id": "JavaScript/134", "prompt": "/* Create a function that returns true if the last character\n of a given string is an alphabetical character and is not\n a part of a word, and false otherwise.\n Note: \"word\" is a group of characters separated by space.\n Examples:\n checkIfLastCharIsALetter(\"apple pie\") \u279e false\n checkIfLastCharIsALetter(\"apple pi e\") \u279e true\n checkIfLastCharIsALetter(\"apple pi e \") \u279e false\n checkIfLastCharIsALetter(\"\") \u279e false\n */\nconst checkIfLastCharIsALetter = (txt) => {\n", "canonical_solution": " let len = txt.length\n if (len == 0) { return false }\n let y = txt[len - 1].charCodeAt()\n if (len == 1) {\n if ((y >= 65 && y <= 90) || (y >= 97 && y <= 122)) { return true }\n return false\n }\n if (txt[len - 2] == ' ' && ((y >= 65 && y <= 90) || (y >= 97 && y <= 122))) { return true }\n return false\n}\n\n", "test": "const testCheckIfLastCharIsALetter = () => {\n console.assert(checkIfLastCharIsALetter('apple') === false)\n console.assert(checkIfLastCharIsALetter('apple pi e') === true)\n console.assert(checkIfLastCharIsALetter('eeeee') === false)\n console.assert(checkIfLastCharIsALetter('A') === true)\n console.assert(checkIfLastCharIsALetter('Pumpkin pie ') === false)\n console.assert(checkIfLastCharIsALetter('Pumpkin pie 1') === false)\n console.assert(checkIfLastCharIsALetter('') === false)\n console.assert(checkIfLastCharIsALetter('eeeee e ') === false)\n console.assert(checkIfLastCharIsALetter('apple pie') === false)\n console.assert(checkIfLastCharIsALetter('apple pi e ') === false)\n}\n\ntestCheckIfLastCharIsALetter()\n", "declaration": "\nconst checkIfLastCharIsALetter = (txt) => {\n", "example_test": "const testCheckIfLastCharIsALetter = () => {\n console.assert(checkIfLastCharIsALetter('apple pi e') === true)\n console.assert(checkIfLastCharIsALetter('') === false)\n console.assert(checkIfLastCharIsALetter('apple pie') === false)\n console.assert(checkIfLastCharIsALetter('apple pi e ') === false)\n}\ntestCheckIfLastCharIsALetter()\n", "buggy_solution": " let len = txt.length\n if (len == 0) { return false }\n let y = txt[len - 1].charCodeAt()\n if (len == 1) {\n if ((y >= 0 && y <= 22) || (y >= 30 && y <= 54)) { return true }\n return false\n }\n if (txt[len - 2] == ' ' && ((y >= 150 && y <= 200) || (y >= 250 && y <= 300))) { return true }\n return false\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "CheckIfLastCharIsALetter"} {"task_id": "JavaScript/135", "prompt": "/*Create a function which returns the largest index of an element which\n is not greater than or equal to the element immediately preceding it. If\n no such element exists then return -1. The given array will not contain\n duplicate values.\n\n Examples:\n canArrange([1,2,4,3,5]) = 3\n canArrange([1,2,3]) = -1\n */\nconst canArrange = (arr) => {\n", "canonical_solution": " if (arr.length == 0) { return -1 }\n for (let i = arr.length - 1; i > 0; i--) {\n if (arr[i] < arr[i - 1]) { return i }\n }\n return -1\n}\n\n", "test": "const testCanArrange = () => {\n console.assert(canArrange([1, 2, 4, 3, 5]) === 3)\n console.assert(canArrange([1, 2, 4, 5]) === -1)\n console.assert(canArrange([1, 4, 2, 5, 6, 7, 8, 9, 10]) === 2)\n console.assert(canArrange([4, 8, 5, 7, 3]) === 4)\n console.assert(canArrange([]) === -1)\n}\n\ntestCanArrange()\n", "declaration": "\nconst canArrange = (arr) => {\n", "example_test": "const testCanArrange = () => {\n console.assert(canArrange([1, 2, 4, 3, 5]) === 3)\n console.assert(canArrange([1, 2, 3]) === -1)\n}\ntestCanArrange()\n", "buggy_solution": " if (arr.length == 0) { return -1 }\n for (let i = arr.length - 1; i > 0; i--) {\n if (arr[i] < arr[i - 1]) { return i + arr[i] }\n }\n return -1\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "CanArrange"} -{"task_id": "JavaScript/136", "prompt": "/* Create a function that returns a tuple (a, b), where 'a' is\n the largest of negative integers, and 'b' is the smallest\n of positive integers in a list.\n If there is no negative or positive integers, return them as null.\n Examples:\n largestSmallestIntegers([2, 4, 1, 3, 5, 7]) == (null, 1)\n largestSmallestIntegers([]) == (null, null)\n largestSmallestIntegers([0]) == (null, null)\n */\nconst largestSmallestIntegers = (lst) => {\n", "canonical_solution": " let a = Infinity\n let b = -Infinity\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] > 0 && lst[i] < a) { a = lst[i] }\n if (lst[i] < 0 && lst[i] > b) { b = lst[i] }\n }\n if (a == Infinity) { a = null }\n if (b == -Infinity) { b = null }\n return (b, a)\n}\n\n", "test": "const testLargestSmallestIntegers = () => {\n console.assert(\n JSON.stringify(largestSmallestIntegers([2, 4, 1, 3, 5, 7])) ===\n JSON.stringify((null, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([2, 4, 1, 3, 5, 7, 0])) ===\n JSON.stringify((null, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([1, 3, 2, 4, 5, 6, -2])) ===\n JSON.stringify((-2, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([4, 5, 3, 6, 2, 7, -7])) ===\n JSON.stringify((-7, 2))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([7, 3, 8, 4, 9, 2, 5, -9])) ===\n JSON.stringify((-9, 2))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([])) === JSON.stringify((null, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([0])) ===\n JSON.stringify((null, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-1, -3, -5, -6])) ===\n JSON.stringify((-1, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-1, -3, -5, -6, 0])) ===\n JSON.stringify((-1, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-6, -4, -4, -3, 1])) ===\n JSON.stringify((-3, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-6, -4, -4, -3, -100, 1])) ===\n JSON.stringify((-3, 1))\n )\n}\n\ntestLargestSmallestIntegers()\n", "declaration": "\nconst largestSmallestIntegers = (lst) => {\n", "example_test": "const testLargestSmallestIntegers = () => {\n console.assert(\n JSON.stringify(largestSmallestIntegers([2, 4, 1, 3, 5, 7])) ===\n JSON.stringify((null, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([])) === JSON.stringify((null, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([0])) ===\n JSON.stringify((null, null))\n )\n}\ntestLargestSmallestIntegers()\n", "buggy_solution": " let a = Infinity\n let b = -Infinity\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] > 0 && lst[i] < a) { a = lst[i] }\n if (lst[i] < 0 && lst[i] > b) { b = lst[i] }\n if (lst[i] < a && 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/136", "prompt": "/* Create a function that returns a tuple (a, b), where 'a' is\n the largest of negative integers, and 'b' is the smallest\n of positive integers in a list.\n If there is no negative or positive integers, return them as null.\n Examples:\n largestSmallestIntegers([2, 4, 1, 3, 5, 7]) == (null, 1)\n largestSmallestIntegers([]) == (null, null)\n largestSmallestIntegers([0]) == (null, null)\n */\nconst largestSmallestIntegers = (lst) => {\n", "canonical_solution": " let a = Infinity\n let b = -Infinity\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] > 0 && lst[i] < a) { a = lst[i] }\n if (lst[i] < 0 && lst[i] > b) { b = lst[i] }\n }\n if (a == Infinity) { a = null }\n if (b == -Infinity) { b = null }\n return (b, a)\n}\n\n", "test": "const testLargestSmallestIntegers = () => {\n console.assert(\n JSON.stringify(largestSmallestIntegers([2, 4, 1, 3, 5, 7])) ===\n JSON.stringify((null, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([2, 4, 1, 3, 5, 7, 0])) ===\n JSON.stringify((null, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([1, 3, 2, 4, 5, 6, -2])) ===\n JSON.stringify((-2, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([4, 5, 3, 6, 2, 7, -7])) ===\n JSON.stringify((-7, 2))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([7, 3, 8, 4, 9, 2, 5, -9])) ===\n JSON.stringify((-9, 2))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([])) === JSON.stringify((null, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([0])) ===\n JSON.stringify((null, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-1, -3, -5, -6])) ===\n JSON.stringify((-1, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-1, -3, -5, -6, 0])) ===\n JSON.stringify((-1, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-6, -4, -4, -3, 1])) ===\n JSON.stringify((-3, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([-6, -4, -4, -3, -100, 1])) ===\n JSON.stringify((-3, 1))\n )\n}\n\ntestLargestSmallestIntegers()\n", "declaration": "\nconst largestSmallestIntegers = (lst) => {\n", "example_test": "const testLargestSmallestIntegers = () => {\n console.assert(\n JSON.stringify(largestSmallestIntegers([2, 4, 1, 3, 5, 7])) ===\n JSON.stringify((null, 1))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([])) === JSON.stringify((null, null))\n )\n console.assert(\n JSON.stringify(largestSmallestIntegers([0])) ===\n JSON.stringify((null, null))\n )\n}\ntestLargestSmallestIntegers()\n", "buggy_solution": " let a = Infinity\n let b = -Infinity\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] > 0 && lst[i] < a) { a = lst[i] }\n if (lst[i] < 0 && lst[i] > b) { b = lst[i] }\n if (lst[i] < a) { b = a }\n if (lst[i] < b) { a = b }\n }\n if (a == Infinity) { a = null }\n if (b == -Infinity) { b = null }\n return (b, a)\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "LargestSmallestIntegers"} {"task_id": "JavaScript/137", "prompt": "/*\n Create a function that takes integers, floats, or strings representing\n real numbers, and returns the larger variable in its given variable type.\n Return null if the values are equal.\n Note: If a real number is represented as a string, the floating point might be . or ,\n\n compareOne(1, 2.5) \u279e 2.5\n compareOne(1, \"2,3\") \u279e \"2,3\"\n compareOne(\"5,1\", \"6\") \u279e \"6\"\n compareOne(\"1\", 1) \u279e null\n */\nconst compareOne = (a, b) => {\n", "canonical_solution": " let aa = Number(a)\n if (typeof a == 'string') { aa = Number(a.replace(',', '.')) }\n let bb = Number(b)\n if (typeof b == 'string') { bb = Number(b.replace(',', '.')) }\n if (aa > bb) { return a }\n if (aa < bb) { return b }\n return null\n}\n\n", "test": "const testCompareOne = () => {\n console.assert(compareOne(1, 2) === 2)\n console.assert(compareOne(1, 2.5) === 2.5)\n console.assert(compareOne(2, 3) === 3)\n console.assert(compareOne(5, 6) === 6)\n console.assert(compareOne(1, '2,3') === '2,3')\n console.assert(compareOne('5,1', '6') === '6')\n console.assert(compareOne('1', '2') === '2')\n console.assert(compareOne('1', 1) === null)\n}\n\ntestCompareOne()\n", "declaration": "\nconst compareOne = (a, b) => {\n", "example_test": "const testCompareOne = () => {\n console.assert(compareOne(1, 2.5) === 2.5)\n console.assert(compareOne(1, '2,3') === '2,3')\n console.assert(compareOne('5,1', '6') === '6')\n console.assert(compareOne('1', 1) === null)\n}\ntestCompareOne()\n", "buggy_solution": " let aa = Number(a)\n if (typeof a == 'string') { aa = Number(a.replace(',', '.').replace('.', ',')) }\n let bb = Number(b)\n if (typeof b == 'string') { bb = Number(b.replace(',', '.')) }\n if (aa > bb) { return a }\n if (aa < bb) { return b }\n return null\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "CompareOne"} {"task_id": "JavaScript/138", "prompt": "/*Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers\n Example\n isEqualToSumEven(4) == false\n isEqualToSumEven(6) == false\n isEqualToSumEven(8) == true\n */\nconst isEqualToSumEven = (n) => {\n", "canonical_solution": " return (n >= 8 && n % 2 == 0)\n}\n\n", "test": "const testIsEqualToSumEven = () => {\n console.assert(isEqualToSumEven(4) === false)\n console.assert(isEqualToSumEven(6) === false)\n console.assert(isEqualToSumEven(8) === true)\n console.assert(isEqualToSumEven(10) === true)\n console.assert(isEqualToSumEven(11) === false)\n console.assert(isEqualToSumEven(12) === true)\n console.assert(isEqualToSumEven(13) === false)\n console.assert(isEqualToSumEven(16) === true)\n}\n\ntestIsEqualToSumEven()\n", "declaration": "\nconst isEqualToSumEven = (n) => {\n", "example_test": "const testIsEqualToSumEven = () => {\n console.assert(isEqualToSumEven(4) === false)\n console.assert(isEqualToSumEven(6) === false)\n console.assert(isEqualToSumEven(8) === true)\n}\ntestIsEqualToSumEven()\n", "buggy_solution": " return (n >= 8 && n <= 8 && n % 2 == 0)\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "IsEqualToSumEven"} {"task_id": "JavaScript/139", "prompt": "/*The Brazilian factorial is defined as:\n brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\n where n > 0\n\n For example:\n >>> specialFactorial(4)\n 288\n\n The function will receive an integer as input and should return the special\n factorial of this integer.\n */\nconst specialFactorial = (n) => {\n", "canonical_solution": " let p = 1;\n let t = 1;\n while (n > 1) {\n let y = p;\n while (y > 0) {\n y--;\n t *= n;\n }\n p++;\n n--;\n }\n return t\n}\n\n", "test": "const testSpecialFactorial = () => {\n console.assert(specialFactorial(4) === 288)\n console.assert(specialFactorial(5) === 34560)\n console.assert(specialFactorial(7) === 125411328000)\n console.assert(specialFactorial(1) === 1)\n}\n\ntestSpecialFactorial()\n", "declaration": "\nconst specialFactorial = (n) => {\n", "example_test": "const testSpecialFactorial = () => {\n console.assert(specialFactorial(4) === 288)\n}\ntestSpecialFactorial()\n", "buggy_solution": " let p = 1;\n let t = 1;\n while (n > 1) {\n let y = p;\n while (y > 0) {\n y--;\n n *= y;\n t *= n;\n }\n p++;\n p++;\n n--;\n }\n return t\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "SpecialFactorial"} -{"task_id": "JavaScript/140", "prompt": "/*\n Given a string text, replace all spaces in it with underscores, \n and if a string has more than 2 consecutive spaces, \n then replace all consecutive spaces with - \n \n fixSpaces(\"Example\") == \"Example\"\n fixSpaces(\"Example 1\") == \"Example_1\"\n fixSpaces(\" Example 2\") == \"_Example_2\"\n fixSpaces(\" Example 3\") == \"_Example-3\"\n */\nconst fixSpaces = (text) => {\n", "canonical_solution": " let t = ''\n let c = 0\n for (let i = 0; i < text.length; i++) {\n if (text[i] == ' ') { c++ }\n else if (c > 0) {\n if (c == 1) { t += '_' }\n if (c == 2) { t += '__' }\n if (c > 2) { t += '-' }\n t += text[i]\n c = 0;\n } else {\n t += text[i]\n }\n }\n if (c == 1) { t += '_' }\n if (c == 2) { t += '__' }\n if (c > 2) { t += '-' }\n return t\n}\n\n", "test": "const testFixSpaces = () => {\n console.assert(fixSpaces('Example') === 'Example')\n console.assert(fixSpaces('Mudasir Hanif ') === 'Mudasir_Hanif_')\n console.assert(\n fixSpaces('Yellow Yellow Dirty Fellow') === 'Yellow_Yellow__Dirty__Fellow'\n )\n console.assert(fixSpaces('Exa mple') === 'Exa-mple')\n console.assert(fixSpaces(' Exa 1 2 2 mple') === '-Exa_1_2_2_mple')\n}\n\ntestFixSpaces()\n", "declaration": "\nconst fixSpaces = (text) => {\n", "example_test": "const testFixSpaces = () => {\n console.assert(fixSpaces('Example') === 'Example')\n console.assert(fixSpaces('Example 1') === 'Example_1')\n console.assert(\n fixSpaces(' Example 2') === '_Example_2'\n )\n console.assert(fixSpaces(' Example 3') === '_Example-3')\n}\ntestFixSpaces()\n", "buggy_solution": " let t = ''\n let c = 0\n for (let i = 0; i < text.length; i++) {\n if (text[i] == ' ') { c++ }\n else if (c > 0) {\n if (c == 1) { t += '_' }\n if (c == 2) { t += '__' }\n if (c > 2) { t += '-' }\n t += text[i]\n c = 0;\n } else {\n t += text[i]\n }\n }\n if (c == 1) { t += '_' }\n if (c == 2) { t += '___' }\n if (c > 2) { t += '-' }\n return t\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "FixSpaces"} +{"task_id": "JavaScript/140", "prompt": "/*\n Given a string text, replace all spaces in it with underscores, \n and if a string has more than 2 consecutive spaces, \n then replace all consecutive spaces with - \n \n fixSpaces(\"Example\") == \"Example\"\n fixSpaces(\"Example 1\") == \"Example_1\"\n fixSpaces(\" Example 2\") == \"_Example_2\"\n fixSpaces(\" Example 3\") == \"_Example-3\"\n */\nconst fixSpaces = (text) => {\n", "canonical_solution": " let t = ''\n let c = 0\n for (let i = 0; i < text.length; i++) {\n if (text[i] == ' ') { c++ }\n else if (c > 0) {\n if (c == 1) { t += '_' }\n if (c == 2) { t += '__' }\n if (c > 2) { t += '-' }\n t += text[i]\n c = 0;\n } else {\n t += text[i]\n }\n }\n if (c == 1) { t += '_' }\n if (c == 2) { t += '__' }\n if (c > 2) { t += '-' }\n return t\n}\n\n", "test": "const testFixSpaces = () => {\n console.assert(fixSpaces('Example') === 'Example')\n console.assert(fixSpaces('Mudasir Hanif ') === 'Mudasir_Hanif_')\n console.assert(\n fixSpaces('Yellow Yellow Dirty Fellow') === 'Yellow_Yellow__Dirty__Fellow'\n )\n console.assert(fixSpaces('Exa mple') === 'Exa-mple')\n console.assert(fixSpaces(' Exa 1 2 2 mple') === '-Exa_1_2_2_mple')\n}\n\ntestFixSpaces()\n", "declaration": "\nconst fixSpaces = (text) => {\n", "example_test": "const testFixSpaces = () => {\n console.assert(fixSpaces('Example') === 'Example')\n console.assert(fixSpaces('Example 1') === 'Example_1')\n console.assert(\n fixSpaces(' Example 2') === '_Example_2'\n )\n console.assert(fixSpaces(' Example 3') === '_Example-3')\n}\ntestFixSpaces()\n", "buggy_solution": " let t = ''\n let c = 0\n for (let i = 0; i < text.length; i++) {\n if (text[i] == ' ') { c++ }\n else if (c > 0) {\n if (c == 1) { t += '_' }\n if (c == 2) { t += '___' }\n if (c > 2) { t += '--' }\n t += text[i]\n c = 0;\n } else {\n t += text[i]\n }\n }\n if (c == 1) { t += '__' }\n if (c == 2) { t += '___' }\n if (c > 2) { t += '-' }\n return t\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "FixSpaces"} {"task_id": "JavaScript/141", "prompt": "/*Create a function which takes a string representing a file's name, and returns\n 'Yes' if the the file's name is valid, and returns 'No' otherwise.\n A file's name is considered to be valid if and only if all the following conditions \n are met:\n - There should not be more than three digits ('0'-'9') in the file's name.\n - The file's name contains exactly one dot '.'\n - The substring before the dot should not be empty, and it starts with a letter from \n the latin alphapet ('a'-'z' and 'A'-'Z').\n - The substring after the dot should be one of these: ['txt', 'exe', 'dll']\n Examples:\n fileNameCheck(\"example.txt\") # => 'Yes'\n fileNameCheck(\"1example.dll\") # => 'No' (the name should start with a latin alphapet letter)\n */\nconst fileNameCheck = (file_name) => {\n", "canonical_solution": " let t = file_name.split(/\\./)\n if (t.length != 2) { return 'No' }\n if (t[1] != 'txt' && t[1] != 'dll' && t[1] != 'exe') { return 'No' }\n if (t[0] == '') { return 'No' }\n let a = t[0][0].charCodeAt()\n if (!((a >= 65 && a <= 90) || (a >= 97 && a <= 122))) { return 'No' }\n let y = 0\n for (let i = 1; i < t[0].length; i++) {\n if (t[0][i].charCodeAt() >= 48 && t[0][i].charCodeAt() <= 57) { y++ }\n if (y > 3) { return 'No' }\n }\n return 'Yes'\n}\n\n", "test": "const testFileNameCheck = () => {\n console.assert(fileNameCheck('example.txt') === 'Yes')\n console.assert(fileNameCheck('1example.dll') === 'No')\n console.assert(fileNameCheck('s1sdf3.asd') === 'No')\n console.assert(fileNameCheck('K.dll') === 'Yes')\n console.assert(fileNameCheck('MY16FILE3.exe') === 'Yes')\n console.assert(fileNameCheck('His12FILE94.exe') === 'No')\n console.assert(fileNameCheck('_Y.txt') === 'No')\n console.assert(fileNameCheck('?aREYA.exe') === 'No')\n console.assert(fileNameCheck('/this_is_valid.dll') === 'No')\n console.assert(fileNameCheck('this_is_valid.wow') === 'No')\n console.assert(fileNameCheck('this_is_valid.txt') === 'Yes')\n console.assert(fileNameCheck('this_is_valid.txtexe') === 'No')\n console.assert(fileNameCheck('#this2_i4s_5valid.ten') === 'No')\n console.assert(fileNameCheck('@this1_is6_valid.exe') === 'No')\n console.assert(fileNameCheck('this_is_12valid.6exe4.txt') === 'No')\n console.assert(fileNameCheck('all.exe.txt') === 'No')\n console.assert(fileNameCheck('I563_No.exe') === 'Yes')\n console.assert(fileNameCheck('Is3youfault.txt') === 'Yes')\n console.assert(fileNameCheck('no_one#knows.dll') === 'Yes')\n console.assert(fileNameCheck('1I563_Yes3.exe') === 'No')\n console.assert(fileNameCheck('I563_Yes3.txtt') === 'No')\n console.assert(fileNameCheck('final..txt') === 'No')\n console.assert(fileNameCheck('final132') === 'No')\n console.assert(fileNameCheck('_f4indsartal132.') === 'No')\n console.assert(fileNameCheck('.txt') === 'No')\n console.assert(fileNameCheck('s.') === 'No')\n}\n\ntestFileNameCheck()\n", "declaration": "\nconst fileNameCheck = (file_name) => {\n", "example_test": "const testFileNameCheck = () => {\n console.assert(fileNameCheck('example.txt') === 'Yes')\n console.assert(fileNameCheck('1example.dll') === 'No')\n}\ntestFileNameCheck()\n", "buggy_solution": " let t = file_name.split(/\\./)\n if (t.length != 2) { return 'No' }\n if (t[0] == '') { return 'No' }\n let a = t[0][0].charCodeAt()\n if (!((a >= 65 && a <= 90) || (a >= 97 && a <= 122))) { return 'No' }\n let y = 0\n for (let i = 1; i < t[0].length; i++) {\n if (t[0][i].charCodeAt() >= 48 && t[0][i].charCodeAt() <= 57) { y++ }\n if (y > 3) { return 'No' }\n }\n return 'Yes'\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "FileNameCheck"} {"task_id": "JavaScript/142", "prompt": "/*\"\n This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a \n multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not \n change the entries in the list whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries. \n \n Examples:\n For lst = [1,2,3] the output should be 6\n For lst = [] the output should be 0\n For lst = [-1,-5,2,-1,-5] the output should be -126\n */\nconst sumSquares = (lst) => {\n", "canonical_solution": " let y = 0\n for (let i = 0; i < lst.length; i++) {\n if (i % 3 == 0) { y += lst[i] * lst[i] }\n else if (i % 4 == 0) { y += lst[i] * lst[i] * lst[i] }\n else { y += lst[i] }\n }\n return y\n}\n\n", "test": "const testSumSquares = () => {\n console.assert(sumSquares([1, 2, 3]) === 6)\n console.assert(sumSquares([1, 4, 9]) === 14)\n console.assert(sumSquares([]) === 0)\n console.assert(sumSquares([1, 1, 1, 1, 1, 1, 1, 1, 1]) === 9)\n console.assert(sumSquares([-1, -1, -1, -1, -1, -1, -1, -1, -1]) === -3)\n console.assert(sumSquares([0]) === 0)\n console.assert(sumSquares([-1, -5, 2, -1, -5]) === -126)\n console.assert(sumSquares([-56, -99, 1, 0, -2]) === 3030)\n console.assert(sumSquares([-1, 0, 0, 0, 0, 0, 0, 0, -1]) === 0)\n console.assert(\n sumSquares([\n -16, -9, -2, 36, 36, 26, -20, 25, -40, 20, -4, 12, -26, 35, 37,\n ]) === -14196\n )\n console.assert(\n sumSquares([\n -1, -3, 17, -1, -15, 13, -1, 14, -14, -12, -5, 14, -14, 6, 13, 11, 16, 16,\n 4, 10,\n ]) === -1448\n )\n}\n\ntestSumSquares()\n", "declaration": "\nconst sumSquares = (lst) => {\n", "example_test": "const testSumSquares = () => {\n console.assert(sumSquares([1, 2, 3]) === 6)\n console.assert(sumSquares([]) === 0)\n console.assert(sumSquares([-1, -5, 2, -1, -5]) === -126)\n}\ntestSumSquares()\n", "buggy_solution": " let y = 0\n for (let i = 0; i < lst.length; i++) {\n if (i % 3 == 0) { y += lst[i] * lst[i] }\n else { y += lst[i] }\n }\n return y\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "SumSquares"} {"task_id": "JavaScript/143", "prompt": "/*\n You are given a string representing a sentence,\n the sentence contains some words separated by a space,\n and you have to return a string that contains the words from the original sentence,\n whose lengths are prime numbers,\n the order of the words in the new string should be the same as the original one.\n\n Example 1:\n Input: sentence = \"This is a test\"\n Output: \"is\"\n\n Example 2:\n Input: sentence = \"lets go for swimming\"\n Output: \"go for\"\n\n Constraints:\n * 1 <= len(sentence) <= 100\n * sentence contains only letters\n */\nconst wordsInSentence = (sentence) => {\n", "canonical_solution": " let t = sentence.split(/\\s/)\n let p = ''\n for (let j = 0; j < t.length; j++) {\n let len = t[j].length;\n let u = 1\n if (len == 1 || len == 0) { continue }\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { u = 0 }\n }\n if (u == 0) { continue }\n if (p == '') { p += t[j] }\n else { p = p + ' ' + t[j] }\n }\n return p\n}\n\n", "test": "const testWordsInSentence = () => {\n console.assert(wordsInSentence('This is a test') === 'is')\n console.assert(wordsInSentence('lets go for swimming') === 'go for')\n console.assert(\n wordsInSentence('there is no place available here') === 'there is no place'\n )\n console.assert(wordsInSentence('Hi I am Hussein') === 'Hi am Hussein')\n console.assert(wordsInSentence('go for it') === 'go for it')\n console.assert(wordsInSentence('here') === '')\n console.assert(wordsInSentence('here is') === 'is')\n}\n\ntestWordsInSentence()\n", "declaration": "\nconst wordsInSentence = (sentence) => {\n", "example_test": "const testWordsInSentence = () => {\n console.assert(wordsInSentence('This is a test') === 'is')\n console.assert(wordsInSentence('lets go for swimming') === 'go for')\n}\ntestWordsInSentence()\n", "buggy_solution": " let t = sentence.split(/\\s/)\n let p = ''\n for (let j = 0; j < t.length; j++) {\n let len = t[j].length;\n let u = 1\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { u = 0 }\n }\n if (u == 0) { continue }\n if (p == '') { p += t[j] }\n else { p = p + ' ' + t[j] }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "WordsInSentence"} @@ -149,8 +149,8 @@ {"task_id": "JavaScript/148", "prompt": "/* There are eight planets in our solar system: the closerst to the Sun\n is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,\n Uranus, Neptune.\n Write a function that takes two planet names as strings planet1 and planet2.\n The function should return a tuple containing all planets whose orbits are\n located between the orbit of planet1 and the orbit of planet2, sorted by\n the proximity to the sun.\n The function should return an empty tuple if planet1 or planet2\n are not correct planet names.\n Examples\n bf(\"Jupiter\", \"Neptune\") ==> (\"Saturn\", \"Uranus\")\n bf(\"Earth\", \"Mercury\") ==> (\"Venus\")\n bf(\"Mercury\", \"Uranus\") ==> (\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\")\n */\nconst bf = (planet1, planet2) => {\n", "canonical_solution": " let y = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']\n let u = []\n let lo = -1\n let hi = -1\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet1) { lo = i }\n }\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet2) { hi = i }\n }\n if (lo == -1 || hi == -1 || lo == hi) { return [] }\n if (lo > hi) {\n let tmp = lo;\n lo = hi;\n hi = tmp;\n }\n for (let i = lo + 1; i < hi; i++) {\n u.push(y[i])\n }\n return u\n}\n\n", "test": "const testBf = () => {\n console.assert(\n JSON.stringify(bf('Jupiter', 'Neptune')) ===\n JSON.stringify(['Saturn', 'Uranus'])\n )\n console.assert(\n JSON.stringify(bf('Earth', 'Mercury')) === JSON.stringify(['Venus'])\n )\n console.assert(\n JSON.stringify(bf('Mercury', 'Uranus')) ===\n JSON.stringify(['Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn'])\n )\n console.assert(\n JSON.stringify(bf('Neptune', 'Venus')) ===\n JSON.stringify(['Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus'])\n )\n console.assert(JSON.stringify(bf('Earth', 'Earth')) === JSON.stringify([]))\n console.assert(JSON.stringify(bf('Mars', 'Earth')) === JSON.stringify([]))\n console.assert(\n JSON.stringify(bf('Jupiter', 'Makemake')) === JSON.stringify([])\n )\n}\n\ntestBf()\n", "declaration": "\nconst bf = (planet1, planet2) => {\n", "example_test": "const testBf = () => {\n console.assert(\n JSON.stringify(bf('Jupiter', 'Neptune')) ===\n JSON.stringify(['Saturn', 'Uranus'])\n )\n console.assert(\n JSON.stringify(bf('Earth', 'Mercury')) === JSON.stringify(['Venus'])\n )\n console.assert(\n JSON.stringify(bf('Mercury', 'Uranus')) ===\n JSON.stringify(['Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn'])\n )\n}\ntestBf()\n", "buggy_solution": " let y = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupyter', 'Saturn', 'Uranus', 'Neptune']\n let u = []\n let lo = -1\n let hi = -1\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet1) { lo = i }\n }\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet2) { hi = i }\n }\n if (lo == -1 || hi == -1 || lo == hi) { return [] }\n if (lo > hi) {\n let tmp = lo;\n lo = hi;\n hi = tmp;\n }\n for (let i = lo + 1; i < hi; i++) {\n u.push(y[i])\n }\n return u\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Bf"} {"task_id": "JavaScript/149", "prompt": "/*Write a function that accepts a list of strings as a parameter,\n deletes the strings that have odd lengths from it,\n and returns the resulted list with a sorted order,\n The list is always a list of strings and never an array of numbers,\n and it may contain duplicates.\n The order of the list should be ascending by length of each word, and you\n should return the list sorted by that rule.\n If two words have the same length, sort the list alphabetically.\n The function should return a list of strings in sorted order.\n You may assume that all words will have the same length.\n For example:\n assert list_sort([\"aa\", \"a\", \"aaa\"]) => [\"aa\"]\n assert list_sort([\"ab\", \"a\", \"aaa\", \"cd\"]) => [\"ab\", \"cd\"]\n */\nconst sortedListSum = (lst) => {\n", "canonical_solution": " let p = []\n for (let i = 0; i < lst.length; i++) {\n if (lst[i].length % 2 == 0) {\n p.push(lst[i])\n }\n }\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let f = 0\n if (p[k].length > p[k + 1].length) { f = 1 }\n if (p[k].length == p[k + 1].length) {\n let r = p[k].length\n for (let l = 0; l < r; l++) {\n if (p[k][l].charCodeAt() > p[k + 1][l].charCodeAt()) {\n f = 1;\n break;\n }\n if (p[k][l].charCodeAt() < p[k + 1][l].charCodeAt()) {\n break;\n }\n }\n }\n if (f == 1) {\n let tmp = p[k]\n p[k] = p[k + 1]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "test": "const testSortedListSum = () => {\n console.assert(\n JSON.stringify(sortedListSum(['aa', 'a', 'aaa'])) === JSON.stringify(['aa'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['school', 'AI', 'asdf', 'b'])) ===\n JSON.stringify(['AI', 'asdf', 'school'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['d', 'b', 'c', 'a'])) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(sortedListSum(['d', 'dcba', 'abcd', 'a'])) ===\n JSON.stringify(['abcd', 'dcba'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['AI', 'ai', 'au'])) ===\n JSON.stringify(['AI', 'ai', 'au'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['a', 'b', 'b', 'c', 'c', 'a'])) ===\n JSON.stringify([])\n )\n console.assert(\n JSON.stringify(sortedListSum(['aaaa', 'bbbb', 'dd', 'cc'])) ===\n JSON.stringify(['cc', 'dd', 'aaaa', 'bbbb'])\n )\n}\n\ntestSortedListSum()\n", "declaration": "\nconst sortedListSum = (lst) => {\n", "example_test": "const testSortedListSum = () => {\n console.assert(\n JSON.stringify(sortedListSum(['aa', 'a', 'aaa'])) === JSON.stringify(['aa'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['ab', 'a', 'aaa', 'cd'])) ===\n JSON.stringify(['ab', 'cd'])\n )\n}\ntestSortedListSum()\n", "buggy_solution": " let p = []\n for (let i = 0; i < lst.length; i++) {\n if (lst[i].length % 2 == 0) {\n p.push(lst[i])\n }\n }\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let f = 0\n if (p[k].length > p[k + 1].length) { f = 1 }\n if (p[k].length == p[k + 1].length) {\n let r = p[k].length\n for (let l = 0; l < r; l++) {\n if (p[k][l].charCodeAt() > p[k + 1][l].charCodeAt()) {\n f = 1;\n break;\n }\n if (p[k][l].charCodeAt() < p[k + 1][l].charCodeAt()) {\n break;\n }\n }\n }\n if (f == 1) {\n let tmp = p[k]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "SortedListSum"} {"task_id": "JavaScript/150", "prompt": "/*A simple program which should return the value of x if n is \n a prime number and should return the value of y otherwise.\n\n Examples:\n for xOrY(7, 34, 12) == 34\n for xOrY(15, 8, 5) == 5\n \n */\nconst xOrY = (n, x, y) => {\n", "canonical_solution": " let len = n\n if (len == 1 || len == 0) { return y }\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { return y }\n }\n return x\n}\n\n", "test": "const testXOrY = () => {\n console.assert(xOrY(7, 34, 12) === 34)\n console.assert(xOrY(15, 8, 5) === 5)\n console.assert(xOrY(3, 33, 5212) === 33)\n console.assert(xOrY(1259, 3, 52) === 3)\n console.assert(xOrY(7919, -1, 12) === -1)\n console.assert(xOrY(3609, 1245, 583) === 583)\n console.assert(xOrY(91, 56, 129) === 129)\n console.assert(xOrY(6, 34, 1234) === 1234)\n console.assert(xOrY(1, 2, 0) === 0)\n console.assert(xOrY(2, 2, 0) === 2)\n}\n\ntestXOrY()\n", "declaration": "\nconst xOrY = (n, x, y) => {\n", "example_test": "const testXOrY = () => {\n console.assert(xOrY(7, 34, 12) === 34)\n console.assert(xOrY(15, 8, 5) === 5)\n}\ntestXOrY()\n", "buggy_solution": " let len = n\n if (len == 1 || len == 0) { return y }\n for (let i = 2; i * i <= len; i++) {\n if (len % i - 1 == 0) { return y }\n }\n return x\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "XOrY"} -{"task_id": "JavaScript/151", "prompt": "/* Given a list of numbers, return the sum of squares of the numbers\n in the list that are odd. Ignore numbers that are negative or not integers.\n doubleTheDifference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10\n doubleTheDifference([-1, -2, 0]) == 0\n doubleTheDifference([9, -2]) == 81\n doubleTheDifference([0]) == 0\n If the input list is empty, return 0.\n */\nconst doubleTheDifference = (lst) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] % 2 == 1 && lst[i] > 0) {\n p += lst[i] * lst[i]\n }\n }\n return p\n}\n\n", "test": "const testDoubleTheDifference = () => {\n console.assert(doubleTheDifference([]) === 0)\n console.assert(doubleTheDifference([5, 4]) === 25)\n console.assert(doubleTheDifference([0.1, 0.2, 0.3]) === 0)\n console.assert(doubleTheDifference([-10, -20, -30]) === 0)\n console.assert(doubleTheDifference([-1, -2, 8]) === 0)\n console.assert(doubleTheDifference([0.2, 3, 5]) === 34)\n let lst = []\n let odd_sum = 0\n for (let i = -99; i < 100; i += 2) {\n if (i % 2 != 0 && i > 0) { odd_sum += i * i }\n lst.push(i)\n }\n console.assert(doubleTheDifference(lst) === odd_sum)\n}\n", "declaration": "\nconst doubleTheDifference = (lst) => {\n", "example_test": "const testDoubleTheDifference = () => {\n console.assert(doubleTheDifference([1,3,2,0]) === 10)\n console.assert(doubleTheDifference([-1,-2,0]) === 0)\n console.assert(doubleTheDifference([9,-2]) === 81)\n console.assert(doubleTheDifference([0]) === 0)\n}\ntestDoubleTheDifference()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] > 0) {\n p += lst[i] * lst[i]\n }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "DoubleTheDifference"} -{"task_id": "JavaScript/152", "prompt": "/*I think we all remember that feeling when the result of some long-awaited\n event is finally known. The feelings and thoughts you have at that moment are\n definitely worth noting down and comparing.\n Your task is to determine if a person correctly guessed the results of a number of matches.\n You are given two arrays of scores and guesses of equal length, where each index shows a match. \n Return an array of the same length denoting how far off each guess was. If they have guessed correctly,\n the value is 0, and if not, the value is the absolute difference between the guess and the score.\n \n \n example:\n\n compare([1,2,3,4,5,1],[1,2,3,4,2,-2]) -> [0,0,0,0,3,3]\n compare([0,5,0,0,0,4],[4,1,1,0,0,-2]) -> [4,4,1,0,0,6]\n */\nconst compare = (game, guess) => {\n", "canonical_solution": " for (let i = 0; i < guess.length; i++) {\n game[i] -= guess[i]\n if (game[i]<0)\n game[i]=-game[i]; }\n return game\n}\n\n", "test": "const testCompare = () => {\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0,5,0,0,0,4],[4,1,1,0,0,-2])) ===\n JSON.stringify([4,4,1,0,0,6])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0])) ===\n JSON.stringify([0, 0, 0, 0, 0, 0])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3], [-1, -2, -3])) ===\n JSON.stringify([2, 4, 6])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3, 5], [-1, 2, 3, 4])) ===\n JSON.stringify([2, 0, 0, 1])\n )\n}\n\ntestCompare()\n", "declaration": "\nconst compare = (game, guess) => {\n", "example_test": "const testCompare = () => {\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0,5,0,0,0,4],[4,1,1,0,0,-2])) ===\n JSON.stringify([4,4,1,0,0,6])\n )\n}\ntestCompare()\n", "buggy_solution": " for (let i = 0; i < guess.length; i++) {\n game[i] -= guess[i]\n if (game[i]<0)\n game[i]=-game[i];\n if (guess[i]<0)\n guess[i]=-guess[i]; }\n return game\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Compare"} +{"task_id": "JavaScript/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]\n }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "DoubleTheDifference"} +{"task_id": "JavaScript/152", "prompt": "/*I think we all remember that feeling when the result of some long-awaited\n event is finally known. The feelings and thoughts you have at that moment are\n definitely worth noting down and comparing.\n Your task is to determine if a person correctly guessed the results of a number of matches.\n You are given two arrays of scores and guesses of equal length, where each index shows a match. \n Return an array of the same length denoting how far off each guess was. If they have guessed correctly,\n the value is 0, and if not, the value is the absolute difference between the guess and the score.\n \n \n example:\n\n compare([1,2,3,4,5,1],[1,2,3,4,2,-2]) -> [0,0,0,0,3,3]\n compare([0,5,0,0,0,4],[4,1,1,0,0,-2]) -> [4,4,1,0,0,6]\n */\nconst compare = (game, guess) => {\n", "canonical_solution": " for (let i = 0; i < guess.length; i++) {\n game[i] -= guess[i]\n if (game[i]<0)\n game[i]=-game[i]; }\n return game\n}\n\n", "test": "const testCompare = () => {\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0,5,0,0,0,4],[4,1,1,0,0,-2])) ===\n JSON.stringify([4,4,1,0,0,6])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0])) ===\n JSON.stringify([0, 0, 0, 0, 0, 0])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3], [-1, -2, -3])) ===\n JSON.stringify([2, 4, 6])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3, 5], [-1, 2, 3, 4])) ===\n JSON.stringify([2, 0, 0, 1])\n )\n}\n\ntestCompare()\n", "declaration": "\nconst compare = (game, guess) => {\n", "example_test": "const testCompare = () => {\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0,5,0,0,0,4],[4,1,1,0,0,-2])) ===\n JSON.stringify([4,4,1,0,0,6])\n )\n}\ntestCompare()\n", "buggy_solution": " for (let i = 0; i < guess.length; i++) {\n game[i] -= guess[i]\n if (game[i]<0)\n game[i]=-game[i];\n if (guess[i]!=0)\n game[i]-=guess[i]; }\n return game\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Compare"} {"task_id": "JavaScript/153", "prompt": "/*You will be given the name of a class (a string) and a list of extensions.\n The extensions are to be used to load additional classes to the class. The\n strength of the extension is as follows: Let CAP be the number of the uppercase\n letters in the extension's name, and let SM be the number of lowercase letters\n in the extension's name, the strength is given by the fraction CAP - SM.\n You should find the strongest extension and return a string in this\n format: ClassName.StrongestExtensionName.\n If there are two or more extensions with the same strength, you should\n choose the one that comes first in the list.\n For example, if you are given \"Slices\" as the class and a list of the\n extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should\n return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension\n (its strength is -1).\n Example:\n for strongestExtension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA'\n */\nconst strongestExtension = (class_name, extensions) => {\n", "canonical_solution": " let u = 0\n let s = -Infinity\n for (let i = extensions.length - 1; i >= 0; i--) {\n let y = 0\n for (let j = 0; j < extensions[i].length; j++) {\n let k = extensions[i][j].charCodeAt()\n if (k >= 65 && k <= 90) { y += 1 }\n if (k >= 97 && k <= 122) { y -= 1 }\n }\n if (y >= s) {\n s = y;\n u = i;\n }\n }\n return class_name + '.' + extensions[u]\n}\n\n", "test": "const testStrongestExtension = () => {\n console.assert(\n strongestExtension('Watashi', ['tEN', 'niNE', 'eIGHt8OKe']) ===\n 'Watashi.eIGHt8OKe'\n )\n console.assert(\n strongestExtension('Boku123', [\n 'nani',\n 'NazeDa',\n 'YEs.WeCaNe',\n '32145tggg',\n ]) === 'Boku123.YEs.WeCaNe'\n )\n console.assert(\n strongestExtension('__YESIMHERE', [\n 't',\n 'eMptY',\n 'nothing',\n 'zeR00',\n 'NuLl__',\n '123NoooneB321',\n ]) === '__YESIMHERE.NuLl__'\n )\n console.assert(\n strongestExtension('K', ['Ta', 'TAR', 't234An', 'cosSo']) === 'K.TAR'\n )\n console.assert(\n strongestExtension('__HAHA', ['Tab', '123', '781345', '-_-']) ===\n '__HAHA.123'\n )\n console.assert(\n strongestExtension('YameRore', [\n 'HhAas',\n 'okIWILL123',\n 'WorkOut',\n 'Fails',\n '-_-',\n ]) === 'YameRore.okIWILL123'\n )\n console.assert(\n strongestExtension('finNNalLLly', ['Die', 'NowW', 'Wow', 'WoW']) ===\n 'finNNalLLly.WoW'\n )\n console.assert(strongestExtension('_', ['Bb', '91245']) === '_.Bb')\n console.assert(strongestExtension('Sp', ['671235', 'Bb']) === 'Sp.671235')\n}\n\ntestStrongestExtension()\n", "declaration": "\nconst strongestExtension = (class_name, extensions) => {\n", "example_test": "const testStrongestExtension = () => {\n console.assert(\n strongestExtension('my_class', ['AA', 'Be', 'CC']) ===\n 'my_class.AA'\n )\n}\ntestStrongestExtension()\n", "buggy_solution": " let u = 0\n let s = -Infinity\n for (let i = extensions.length - 1; i >= 0; i--) {\n let y = 0\n for (let j = 0; j < extensions[i].length; j++) {\n let k = extensions[i][j].charCodeAt()\n if (k >= 65 && k <= 90) { y += 1 }\n if (k >= 97 && k <= 122) { y -= 1 }\n }\n if (y >= s) {\n s = y;\n u = i;\n }\n }\n return class_name + extensions[u]\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "StrongestExtension"} {"task_id": "JavaScript/154", "prompt": "/*You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word\n cycpatternCheck(\"abcd\",\"abd\") => false\n cycpatternCheck(\"hello\",\"ell\") => true\n cycpatternCheck(\"whassup\",\"psus\") => false\n cycpatternCheck(\"abab\",\"baa\") => true\n cycpatternCheck(\"efef\",\"eeff\") => false\n cycpatternCheck(\"himenss\",\"simen\") => true\n */\nconst cycpatternCheck = (a, b) => {\n", "canonical_solution": " let l = b.length\n let pat = b + b\n for (let i = 0; i < a.length - l + 1; i++) {\n for (let j = 0; j < l + 1; j++) {\n let y = 1\n for (let k = 0; k < l; k++) {\n if (a[i + k] != pat[j + k]) { y = 0 }\n }\n if (y == 1) {\n return true\n }\n }\n }\n return false\n}\n\n", "test": "const testCycpatternCheck = () => {\n console.assert(cycpatternCheck('xyzw', 'xyw') === false)\n console.assert(cycpatternCheck('yello', 'ell') === true)\n console.assert(cycpatternCheck('whattup', 'ptut') === false)\n console.assert(cycpatternCheck('efef', 'fee') === true)\n console.assert(cycpatternCheck('abab', 'aabb') === false)\n console.assert(cycpatternCheck('winemtt', 'tinem') === true)\n}\n\ntestCycpatternCheck()\n", "declaration": "\nconst cycpatternCheck = (a, b) => {\n", "example_test": "const testCycpatternCheck = () => {\n console.assert(cycpatternCheck('abcd', 'abd') === false)\n console.assert(cycpatternCheck('hello', 'ell') === true)\n console.assert(cycpatternCheck('whassup', 'psus') === false)\n console.assert(cycpatternCheck('abab', 'baa') === true)\n console.assert(cycpatternCheck('efef', 'eeff') === false)\n console.assert(cycpatternCheck('himenss', 'simen') === true)\n}\ntestCycpatternCheck()\n", "buggy_solution": " let l = b.length\n let pat = b + b\n for (let i = 0; i < a.length - l + 1; i++) {\n for (let j = 0; j < b.length - l + 1; j++) {\n let y = 1\n for (let k = 0; k < l; k++) {\n if (a[i + k] != pat[j + k]) { y = 0 }\n }\n if (y == 1) {\n return true\n }\n }\n }\n return false\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "CycpatternCheck"} {"task_id": "JavaScript/155", "prompt": "/*Given an integer. return a tuple that has the number of even and odd digits respectively.\n\n Example:\n evenOddCount(-12) ==> (1, 1)\n evenOddCount(123) ==> (1, 2)\n */\nconst evenOddCount = (num) => {\n", "canonical_solution": " let o = 0\n let e = 0\n if (num < 0) { num = -num }\n while (num > 0) {\n if (num % 2 == 0) { e++ }\n else { o++ }\n num = (num - num % 10) / 10\n }\n return (e, o)\n}\n\n", "test": "const testEvenOddCount = () => {\n console.assert(JSON.stringify(evenOddCount(7)) === JSON.stringify((0, 1)))\n console.assert(JSON.stringify(evenOddCount(-78)) === JSON.stringify((1, 1)))\n console.assert(JSON.stringify(evenOddCount(3452)) === JSON.stringify((2, 2)))\n console.assert(\n JSON.stringify(evenOddCount(346211)) === JSON.stringify((3, 3))\n )\n console.assert(\n JSON.stringify(evenOddCount(-345821)) === JSON.stringify((3, 3))\n )\n console.assert(JSON.stringify(evenOddCount(-2)) === JSON.stringify((1, 0)))\n console.assert(\n JSON.stringify(evenOddCount(-45347)) === JSON.stringify((2, 3))\n )\n console.assert(JSON.stringify(evenOddCount(0)) === JSON.stringify((1, 0)))\n}\n\ntestEvenOddCount()\n", "declaration": "\nconst evenOddCount = (num) => {\n", "example_test": "const testEvenOddCount = () => {\n console.assert(JSON.stringify(evenOddCount(-12)) === JSON.stringify((1, 1)))\n console.assert(JSON.stringify(evenOddCount(123)) === JSON.stringify((1, 2)))\n}\ntestEvenOddCount()\n", "buggy_solution": " let o = 0\n let e = 0\n if (num < 0) { num = -num }\n while (num > 0) {\n if (num % 2 == 0) { e++ }\n else { o++ }\n num = num - num % 10\n }\n return (e, o)\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "EvenOddCount"} @@ -161,4 +161,4 @@ {"task_id": "JavaScript/160", "prompt": "/*\n Given two lists operator, and operand. The first list has basic algebra operations, and \n the second list is a list of integers. Use the two given lists to build the algebric \n expression and return the evaluation of this expression.\n\n The basic algebra operations:\n Addition ( + ) \n Subtraction ( - ) \n Multiplication ( * ) \n Floor division ( // ) \n Exponentiation ( ** ) \n\n Example:\n operator['+', '*', '-']\n array = [2, 3, 4, 5]\n result = 2 + 3 * 4 - 5\n => result = 9\n\n Note:\n The length of operator list is equal to the length of operand list minus one.\n Operand is a list of of non-negative integers.\n Operator list has at least one operator, and operand list has at least two operands.\n\n */\nconst doAlgebra = (operator, operand) => {\n", "canonical_solution": " while (operator.length > 0) {\n let y = 0\n for (let i = operator.length - 1; i >= 0; i--) {\n if (operator[i] == '**') {\n let u = operand[i]\n while (operand[i + 1] > 1) {\n operand[i + 1]--;\n operand[i] *= u;\n }\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n for (let i = 0; i < operator.length; i++) {\n if (operator[i] == '*') {\n operand[i] *= operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n else if (operator[i] == '//') {\n operand[i] = (operand[i] - operand[i] % operand[i + 1]) / operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n for (let i = 0; i < operator.length; i++) {\n if (operator[i] == '+') {\n operand[i] += operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n else if (operator[i] == '-') {\n operand[i] -= operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n }\n return operand[0]\n}\n\n", "test": "const testDoAlgebra = () => {\n console.assert(doAlgebra(['**', '*', '+'], [2, 3, 4, 5]) === 37)\n console.assert(doAlgebra(['+', '*', '-'], [2, 3, 4, 5]) === 9)\n console.assert(doAlgebra(['//', '*'], [7, 3, 4]) === 8)\n}\n\ntestDoAlgebra()\n", "declaration": "\nconst doAlgebra = (operator, operand) => {\n", "example_test": "", "buggy_solution": " while (operator.length > 0) {\n let y = 0\n for (let i = operator.length - 1; i >= 0; i--) {\n if (operator[i] == '**') {\n let u = operand[i]\n while (operand[i + 1] > 1) {\n operand[i + 1]--;\n operand[i] *= u;\n }\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n for (let i = 0; i < operator.length; i++) {\n if (operator[i] == '*') {\n operand[i] *= operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n else if (operator[i] == '//') {\n operand[i] = (operand[i + 1] - operand[i] % operand[i + 1]) / operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n for (let i = 0; i < operator.length; i++) {\n if (operator[i] == '+') {\n operand[i] += operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n else if (operator[i] == '-') {\n operand[i] -= operand[i + 1]\n operand.splice(i + 1, 1)\n operator.splice(i, 1)\n y = 1;\n break;\n }\n }\n if (y == 1) { continue }\n }\n return operand[0]\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "DoAlgebra"} {"task_id": "JavaScript/161", "prompt": "/*You are given a string s.\n if s[i] is a letter, reverse its case from lower to upper or vise versa, \n otherwise keep it as it is.\n If the string contains no letters, reverse the string.\n The function should return the resulted string.\n Examples\n solve(\"1234\") = \"4321\"\n solve(\"ab\") = \"AB\"\n solve(\"#a@C\") = \"#A@c\"\n */\nconst solve = (s) => {\n", "canonical_solution": " let t = 0\n let p = ''\n for (let i = 0; i < s.length; i++) {\n let y = s[i].charCodeAt()\n if (y >= 65 && y <= 90) {\n y += 32;\n t = 1;\n } else if (y >= 97 && y <= 122) {\n y -= 32;\n t = 1;\n }\n p += String.fromCharCode(y)\n }\n if (t == 1) { return p }\n let u = ''\n for (let i = 0; i < p.length; i++) {\n u += p[p.length - i - 1]\n }\n return u\n}\n\n", "test": "const testSolve = () => {\n console.assert(solve('AsDf') === 'aSdF')\n console.assert(solve('1234') === '4321')\n console.assert(solve('ab') === 'AB')\n console.assert(solve('#a@C') === '#A@c')\n console.assert(solve('#AsdfW^45') === '#aSDFw^45')\n console.assert(solve('#6@2') === '2@6#')\n console.assert(solve('#$a^D') === '#$A^d')\n console.assert(solve('#ccc') === '#CCC')\n}\n\ntestSolve()\n", "declaration": "\nconst solve = (s) => {\n", "example_test": "const testSolve = () => {\n console.assert(solve('1234') === '4321')\n console.assert(solve('ab') === 'AB')\n console.assert(solve('#a@C') === '#A@c')\n}\ntestSolve()\n", "buggy_solution": " let t = 0\n let p = ''\n for (let i = 0; i < s.length; i++) {\n let y = s[i].charCodeAt()\n if (y >= 65 && y <= 90) {\n y += 32;\n t = 1;\n }\n p += String.fromCharCode(y)\n }\n if (t == 1) { return p }\n let u = ''\n for (let i = 0; i < p.length; i++) {\n u += p[p.length - i - 1]\n }\n return u\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "Solve"} {"task_id": "JavaScript/162", "prompt": "/*\n Given a string 'text', return its md5 hash equivalent string.\n If 'text' is an empty string, return null.\n\n >>> stringToMd5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'\n */\nconst stringToMd5 = (text) => {\n", "canonical_solution": " if (text == '') { return null }\n var md5 = require('js-md5')\n return md5(text)\n}\n\n", "test": "const testStringToMd5 = () => {\n console.assert(\n stringToMd5('Hello world') === '3e25960a79dbc69b674cd4ec67a72c62'\n )\n console.assert(stringToMd5('') === null)\n console.assert(stringToMd5('A B C') === '0ef78513b0cb8cef12743f5aeb35f888')\n console.assert(stringToMd5('password') === '5f4dcc3b5aa765d61d8327deb882cf99')\n}\n\ntestStringToMd5()\n", "declaration": "\nconst stringToMd5 = (text) => {\n", "example_test": "const testStringToMd5 = () => {\n console.assert(\n stringToMd5('Hello world') === '3e25960a79dbc69b674cd4ec67a72c62'\n )\n}\ntestStringToMd5()\n", "buggy_solution": " if (text == '') { return null }\n var md5 = require('js-md5')\n return md5('text')\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "StringToMd5"} -{"task_id": "JavaScript/163", "prompt": "/*\n Given two positive integers a and b, return the even digits between a\n and b, in ascending order.\n\n For example:\n generateIntegers(2, 8) => [2, 4, 6, 8]\n generateIntegers(8, 2) => [2, 4, 6, 8]\n generateIntegers(10, 14) => []\n */\nconst generateIntegers = (a, b) => {\n", "canonical_solution": " if (a > b) {\n let tmp = a;\n a = b;\n b = tmp;\n }\n let y = []\n for (let i = a; i <= b; i++) {\n if (i == 2 || i == 4 || i == 6 || i == 8) { y.push(i) }\n }\n return y\n}\n\n", "test": "const testGenerateIntegers = () => {\n console.assert(\n JSON.stringify(generateIntegers(2, 10)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(10, 2)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(132, 2)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(17, 89)) === JSON.stringify([])\n )\n}\n\ntestGenerateIntegers()\n", "declaration": "\nconst generateIntegers = (a, b) => {\n", "example_test": "const testGenerateIntegers = () => {\n console.assert(\n JSON.stringify(generateIntegers(2, 8)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(8, 2)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(10, 14)) === JSON.stringify([])\n )\n}\ntestGenerateIntegers()\n", "buggy_solution": " if (a > b) {\n let tmp = a;\n a = b;\n b = tmp;\n }\n let y = []\n for (let i = a; i < b; i++) {\n if (i == 2 || i == 4 || i == 6 || i == 8) { y.push(i) }\n }\n return y\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "GenerateIntegers"} +{"task_id": "JavaScript/163", "prompt": "/*\n Given two positive integers a and b, return the even digits between a\n and b, in ascending order.\n\n For example:\n generateIntegers(2, 8) => [2, 4, 6, 8]\n generateIntegers(8, 2) => [2, 4, 6, 8]\n generateIntegers(10, 14) => []\n */\nconst generateIntegers = (a, b) => {\n", "canonical_solution": " if (a > b) {\n let tmp = a;\n a = b;\n b = tmp;\n }\n let y = []\n for (let i = a; i <= b; i++) {\n if (i == 2 || i == 4 || i == 6 || i == 8) { y.push(i) }\n }\n return y\n}\n\n", "test": "const testGenerateIntegers = () => {\n console.assert(\n JSON.stringify(generateIntegers(2, 10)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(10, 2)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(132, 2)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(17, 89)) === JSON.stringify([])\n )\n}\n\ntestGenerateIntegers()\n", "declaration": "\nconst generateIntegers = (a, b) => {\n", "example_test": "const testGenerateIntegers = () => {\n console.assert(\n JSON.stringify(generateIntegers(2, 8)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(8, 2)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(10, 14)) === JSON.stringify([])\n )\n}\ntestGenerateIntegers()\n", "buggy_solution": " if (a > b) {\n let tmp = a;\n a = b;\n b = tmp;\n }\n let y = []\n for (let i = a; i > b; i++) {\n if (i == 2 || i == 4 || i == 6 || i == 8) { y.push(i) }\n }\n return y\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "GenerateIntegers"}