786. K-th Smallest Prime Fraction

My solution is O(n^2). it is not efficient but accepted.

The official more efficient codes are here!

https://leetcode.com/problems/k-th-smallest-prime-fraction/

var kthSmallestPrimeFraction = function (arr, k) {
  let mat = arr
    .flatMap((v1, i) => arr.slice(i + 1).map((v2) => [v1, v2, v1 / v2]))
    .toSorted((a, b) => a[2] - b[2]);
  let [a, b] = mat[k - 1];
  return [a, b];
};