データと保存

表記の違う重複を見つける

normalize
表記は違っても同じ番号の記録をまとめます。
試す
  • 03-5253-81114
  • 090-1234-56782

しくみ

03-5253-8111、03-5253-8111、(03)5253-8111、+81-3-5253-8111 は、どれも同じ番号です。正規化した値でまとめると、重複した顧客や連絡先が見つかります。

不正な記録は、元の文字をそのままキーにします。人が確かめられるように残すためです。

各言語で

import { normalize } from "@kurashina-design/japan-phone";

// A customer list where the same numbers were typed in different ways.
const entries = ["03-5253-8111", "03-5253-8111", "(03)5253-8111", "+81-3-5253-8111", "090-1234-5678", "09012345678"];

const counts = new Map();
for (const entry of entries) {
  const key = normalize(entry)?.national ?? entry;
  counts.set(key, (counts.get(key) ?? 0) + 1);
}
for (const [number, count] of counts) console.log(`${number}: ${count}`);

出力:

03-5253-8111: 4
090-1234-5678: 2