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.

dataHelper.ts 1.0KB

1 年之前
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. export const findidx : Function = (arr: any, val: any) => {
  2. return arr.findIndex(item => {
  3. return item.id === val
  4. })
  5. }
  6. export const intersectionAlike : Function = (objA: any, objB: any) => {
  7. const result = {};
  8. for (const keyA in objA) {
  9. if (objB.hasOwnProperty(keyA)) {
  10. result[keyA] = objB[keyA];
  11. }
  12. }
  13. return result;
  14. }
  15. export const hasValue : Function = (obj: any) => {
  16. let result = '';
  17. result = Object.keys(obj).filter(key => obj[key] !== 0).map(key => `${obj[key]}`).join('')
  18. return result;
  19. }
  20. export const divObj : Function = (obj: any) => {
  21. const result = []
  22. obj.reduce((acc, curr, index) => {
  23. curr.idx = index;
  24. result.push(curr)
  25. // const key = `node${index}Info`;
  26. // acc[key] = curr;
  27. // return acc;
  28. }, {});
  29. return result;
  30. }
  31. export const alreadyValue: Function = (obj: any) => {
  32. const result = []
  33. obj.reduce((acc, curr, index) => {
  34. curr.idx = index;
  35. result.push(curr)
  36. // const key = `node${index}Info`;
  37. // acc[key] = curr;
  38. // return acc;
  39. }, {});
  40. return result;
  41. }