Advertisement
nodejsdeveloperskh

try-different-solutions

Jul 14th, 2021
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Untitled-1.js
  2.  
  3. /**
  4.  *
  5.  * @param {object[]} fieldScores
  6.  * @param {string} fieldScores.contractorId
  7.  * @param {number} fieldScores.score
  8.  * @param {string} type
  9.  * @returns {{[contractorId: string]: {type: string, score: number}[]}[]}
  10.  */
  11. function demandLeadMatchmakingScores(fieldScores, type) {
  12.   /**@type {{[contractorId: string]: {type: string, score: number}[]}[]} */
  13.   const result = [];
  14.  
  15.   for (let fieldScore of fieldScores) {
  16.     result.push({
  17.       [fieldScore.contractorId]: [
  18.         {
  19.           score: fieldScore.score,
  20.           type,
  21.         },
  22.       ],
  23.     });
  24.   }
  25.  
  26.   return result;
  27. }
  28.  
  29. /**@type {{[contractorId: string]: {type: string, score: number}[]}[]} */
  30. const matchmakingScores = [];
  31.  
  32. const locationScores = [
  33.   { contractorId: "123", score: 32 },
  34.   { contractorId: "321", score: 12 },
  35.   { contractorId: "213", score: 42 },
  36.   { contractorId: "312", score: 60 },
  37.   { contractorId: "313", score: 34 },
  38. ];
  39. const experienceInMaterialScores = [
  40.   { contractorId: "321", score: 12 },
  41.   { contractorId: "123", score: 32 },
  42.   { contractorId: "313", score: 34 },
  43.   { contractorId: "312", score: 60 },
  44.   { contractorId: "213", score: 42 },
  45. ];
  46.  
  47. matchmakingScores.push(
  48.   ...demandLeadMatchmakingScores(locationScores, "LOCATION")
  49. );
  50. matchmakingScores.push(
  51.   ...demandLeadMatchmakingScores(experienceInMaterialScores, "LOCATION")
  52. );
  53.  
  54. console.dir(matchmakingScores, { depth: 4 });
  55.  
  56. // Untitled-2.js
  57. /**
  58.  *
  59.  * @param {object[]} fieldScores
  60.  * @param {string} fieldScores.contractorId
  61.  * @param {number} fieldScores.score
  62.  * @param {string} type
  63.  * @param {[contractorId: string]: {type: string, score: number}[]} matchmakingScores
  64.  */
  65. function demandLeadMatchmakingScores(fieldScores, type, matchmakingScores) {
  66.   for (let fieldScore of fieldScores) {
  67.     if (matchmakingScores[fieldScore.contractorId] === undefined) {
  68.       matchmakingScores[fieldScore.contractorId] = [];
  69.     }
  70.     matchmakingScores[fieldScore.contractorId].push({
  71.       score: fieldScore.score,
  72.       type,
  73.     });
  74.   }
  75. }
  76.  
  77. /**@type {{[contractorId: string]: {type: string, score: number}[]}[]} */
  78. const matchmakingScores = [];
  79.  
  80. const locationScores = [
  81.   { contractorId: "123", score: 32 },
  82.   { contractorId: "321", score: 12 },
  83.   { contractorId: "213", score: 42 },
  84.   { contractorId: "312", score: 60 },
  85.   { contractorId: "313", score: 34 },
  86. ];
  87. const experienceInMaterialScores = [
  88.   { contractorId: "321", score: 12 },
  89.   { contractorId: "123", score: 32 },
  90.   { contractorId: "313", score: 34 },
  91.   { contractorId: "312", score: 60 },
  92.   { contractorId: "213", score: 42 },
  93. ];
  94.  
  95. demandLeadMatchmakingScores(locationScores, "LOCATION", matchmakingScores);
  96. demandLeadMatchmakingScores(
  97.   experienceInMaterialScores,
  98.   "EX",
  99.   matchmakingScores
  100. );
  101.  
  102. console.dir(matchmakingScores, { depth: 4 });
  103.  
  104. // Untitled-3.js
  105. const locationScores = [
  106.   { contractorId: "123", score: 32 },
  107.   { contractorId: "321", score: 12 },
  108.   { contractorId: "213", score: 42 },
  109.   { contractorId: "312", score: 60 },
  110.   { contractorId: "313", score: 34 },
  111. ];
  112. const experienceInMaterialScores = [
  113.   { contractorId: "321", score: 12 },
  114.   { contractorId: "123", score: 32 },
  115.   { contractorId: "313", score: 34 },
  116.   { contractorId: "312", score: 60 },
  117.   { contractorId: "213", score: 42 },
  118. ];
  119.  
  120. matchmaking(
  121.   "60ee8b06a312cd1ed6012136",
  122.   locationScores.map(() => {})
  123. );
  124.  
  125. /**
  126.  *
  127.  * @param {string} demandLeadId
  128.  * @param {{type; string, score: number}[]} matchmakingScores
  129.  */
  130. function matchmaking(demandLeadId, matchmakingScores) {}
  131.  
  132. // Untitled-4.js
  133. const locationScores = [
  134.   { contractorId: "123", score: 32 },
  135.   { contractorId: "321", score: 12 },
  136.   { contractorId: "213", score: 42 },
  137.   { contractorId: "312", score: 60 },
  138.   { contractorId: "313", score: 34 },
  139. ];
  140. const experienceInMaterialScores = [
  141.   { contractorId: "321", score: 12 },
  142.   { contractorId: "123", score: 32 },
  143.   { contractorId: "313", score: 34 },
  144.   { contractorId: "312", score: 60 },
  145.   { contractorId: "213", score: 42 },
  146. ];
  147.  
  148. contractorScores(...locationScores, ...experienceInMaterialScores);
  149.  
  150. function contractorScores(...scores) {
  151.   console.log(scores);
  152.   for (let score of scores) {
  153.     console.log(score.contractorId);
  154.   }
  155. }
  156.  
  157. // the final result
  158. const locationScores = [
  159.   { contractorId: "123", score: 32 },
  160.   { contractorId: "321", score: 12 },
  161.   { contractorId: "213", score: 42 },
  162.   { contractorId: "312", score: 60 },
  163.   { contractorId: "313", score: 34 },
  164. ];
  165. const experienceInMaterialScores = [
  166.   { contractorId: "321", score: 12 },
  167.   { contractorId: "123", score: 32 },
  168.   { contractorId: "313", score: 34 },
  169.   { contractorId: "312", score: 60 },
  170.   { contractorId: "213", score: 42 },
  171. ];
  172.  
  173. const matchmakingScores = []
  174.  
  175. matchmakingScores.push(create(locationScores, "loc", "123"), create(experienceInMaterialScores, 'ex', '123'));
  176.  
  177. console.log(matchmakingScores);
  178.  
  179. function create(scores, type, contractorId) {
  180.     const score = scores.filter(score => score.contractorId === contractorId)[0].score;
  181.  
  182.     return {
  183.         type,
  184.         score,
  185.     }
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement