sortAddress([
{shozai: '東京都港区西新橋3丁目', number: '1ー2'},
{shozai: '東京都港区西新橋3丁目', number: '1ー1'}
])
// __sortKey: '東京都港区西新橋3丁目1ー2' を追加してまとめてやるもよし
const sortAddress = (items) => {
items.sort((a, b) => {
if (a.shozai < b.shozai) {
return -1
} else if (a.shozai > b.shozai) {
return 1
}
return replaceNumberForSort(a.number) < replaceNumberForSort(b.number) ? -1 : 1
})
return items
}
const replaceNumberForSort = (str) => {
str = str.replace(/[0-9]/g, (s) => {
return String.fromCharCode(s.charCodeAt(0) - 65248)
}).replace(/[‐-―ー]/g, '-') // ハイフンにいろんなパターンがある場合があるので
return str.split('-').reduce((acc, item) => {
return acc + item * 100000
}, 0)
}