[JavaScript] 2040. Kth Smallest Product of Two Sorted Arrays
---\n\n- This is compressed answer, not easy to understand at first, core logic is minimal\n\n---\n\nHope it is simple to understand.\n\n---\n\n\nconst lessthan
---\n\n- This is compressed answer, not easy to understand at first, core logic is minimal\n\n---\n\nHope it is simple to understand.\n\n---\n\n```\nconst lessthan_4ge = (a, b) => a < b;\nconst lessthanequal_4g = (a, b) => a <= b;\nfunction blu_midVal4mFunc(compFunc, getMidVal, target, left, right) {\n    while (left < right) {\n        let mid = left + Math.trunc((right - left) / 2);\n        if (compFunc(getMidVal(mid), target)) left = mid + 1;\n        else right = mid;\n    }\n    return compFunc(getMidVal(left), target) ? left + 1 : left;\n}\nvar kthSmallestProduct = function (nums1, nums2, k) {\n    let prod_left = -((10 ** 5) ** 2),                         // from question constraints\n        prod_right = (10 ** 5) ** 2,\n        getMidVal = (mid) => nums2[mid];                       // just arr[mid]\n\n    var getVal = function (prod_mid) {\n        let count = 0;\n        for (let n1 of nums1) {\n            if (n1 > 0)\n                count += blu_midVal4mFunc(lessthan_4ge, getMidVal, prod_mid / n1, 0, nums2.length - 1);\n            else if (n1 < 0)\n                count += nums2.length - blu_midVal4mFunc(lessthanequal_4g, getMidVal, prod_mid / n1, 0, nums2.length - 1);\n            else if (n1 === 0)\n                if (prod_mid > 0)\n                    count += nums2.length;\n        }\n        return count;\n    };\n\n    return blu_midVal4mFunc(lessthan_4ge, getVal, k, prod_left, prod_right) - 1;\n};\n```\n\n---\n
['JavaScript']