MofuMofu2 / typescript-sandbox

MIT License
0 stars 0 forks source link

オブジェクト操作 #34

Closed MofuMofu2 closed 1 year ago

MofuMofu2 commented 1 year ago

デバッグの練習をしたい

const objectList = [
  { id: 1, name: "hoge" },
  { id: 2, name: "fuga" },
  { id: 3, name: "piyo" },
  { id: 4, name: "foo" },
  { id: 5, name: "bar" },
  { id: 6, name: "baz" },
  { id: 7, name: "pamo" },
  { id: 8, name: "buchi" },
  { id: 9, name: "tama" },
  { id: 10, name: "tora" },
]
MofuMofu2 commented 1 year ago

https://tc39.es/ecma262/multipage/text-processing.html#sec-string.prototype.localecompare

This method itself is not directly suitable as an argument to Array.prototype.sort because the latter requires a function of two arguments.

sort((a, b) => a - b)の(a,b)の部分にString.prototype.localeCompareを使わないでね、ということだった。