Find K Closest Element Javascript Solution
in this Problem we are going to use Two Pointers Approach to Solve this Problem easily\nwith the Rules Already Given in the Problem Description\nAn integer a is
in this Problem we are going to use Two Pointers Approach to Solve this Problem easily\nwith the Rules Already Given in the Problem Description\nAn integer a is closer to x than an integer b if:\n|a - x| < |b - x|\n\nSo we will take one Pointer to represent the left Traverse Functionality and one for the right Traverse Functionality\n\n```javascript\nvar findClosestElements = function (arr, k, x) {\n  let leftPointer = 0;\n  let rightPointer = arr.length - 1;\n  while (rightPointer - leftPointer >= k) {\n    // a-x <= b-x (Comparison Law at the Question)\n    if (Math.abs(arr[leftPointer] - x) <= Math.abs(arr[rightPointer] - x)) rightPointer--;\n    else leftPointer++;\n  }\n  return arr.slice(leftPointer, rightPointer + 1);\n};\n```\nUp Vote if you find it Useful guys
['Two Pointers', 'JavaScript']