You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.ts 531B

123456789101112131415161718192021222324
  1. export type FormListItem = {
  2. frequency: number;
  3. tag: string;
  4. };
  5. export function transformTagFeaturesArrayToObject(
  6. list: Array<FormListItem> = [],
  7. ) {
  8. return list.reduce<Record<string, number>>((pre, cur) => {
  9. pre[cur.tag] = cur.frequency;
  10. return pre;
  11. }, {});
  12. }
  13. export function transformTagFeaturesObjectToArray(
  14. object: Record<string, number> = {},
  15. ) {
  16. return Object.keys(object).reduce<Array<FormListItem>>((pre, key) => {
  17. pre.push({ frequency: object[key], tag: key });
  18. return pre;
  19. }, []);
  20. }