function metric(n) {
  for (let i = metricPrefix.length - 1; i >= 0; i--) {
    const limit = metricPower[i]
    const absN = Math.abs(n)
    if (absN >= limit) {
      const scaledN = absN / limit
      if (scaledN < 10) {
        // For "small" numbers, display one decimal digit unless it is 0.
        const oneDecimalN = scaledN.toFixed(1)
        if (oneDecimalN.charAt(oneDecimalN.length - 1) !== '0') {
          const res = `${oneDecimalN}${metricPrefix[i]}`
          return n > 0 ? res : `-${res}`
        }
      }
      const roundedN = Math.round(scaledN)
      if (roundedN < 1000) {
        const res = `${roundedN}${metricPrefix[i]}`
        return n > 0 ? res : `-${res}`
      } else {
        const res = `1${metricPrefix[i + 1]}`
        return n > 0 ? res : `-${res}`
      }
    }
  }
  return `${n}`
}
Given a number (positive or negative), returns a string with appropriate unit in the metric system, SI.
Note: numbers beyond the peta- cannot be represented as integers in JS.
For example, if you call metric(1000), it will return "1k", which means one kilo or one thousand.

@param {number} n - Input number
@returns {string} String with appropriate unit in the metric system, SI