Sort lines in numerical order

Sort a list of numbers in ascending or descending order based on their numerical value. Other items are moved to the end of the list, without changing their order.

Face with waiting expression Nothing to see yet!

Loading takeymakey...
TakeyMakey code
Want this tool to do something else? Edit the code below and make it do whatever you want.
({
  take: [
    { key: "nbs", type: "list", label: "Numbers" },
    { key: "asc", type: "toggle", label: "Sort ascending", value: true },
  ],
  make: ({ nbs, asc }) => {
    const f = asc ? 1 : -1
    const v = (v) => (Number.isNaN(+v) ? f * Infinity : +v)

    nbs.unshift("-- These items weren't sorted --")

    return nbs.sort((a, b) => {
      let [x, y] = [a, b].map(v)
      return x === y ? 0 : f * (x > y ? 1 : -1)
    })
  },
})