Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Untitled-1.js
- /**
- *
- * @param {object[]} fieldScores
- * @param {string} fieldScores.contractorId
- * @param {number} fieldScores.score
- * @param {string} type
- * @returns {{[contractorId: string]: {type: string, score: number}[]}[]}
- */
- function demandLeadMatchmakingScores(fieldScores, type) {
- /**@type {{[contractorId: string]: {type: string, score: number}[]}[]} */
- const result = [];
- for (let fieldScore of fieldScores) {
- result.push({
- [fieldScore.contractorId]: [
- {
- score: fieldScore.score,
- type,
- },
- ],
- });
- }
- return result;
- }
- /**@type {{[contractorId: string]: {type: string, score: number}[]}[]} */
- const matchmakingScores = [];
- const locationScores = [
- { contractorId: "123", score: 32 },
- { contractorId: "321", score: 12 },
- { contractorId: "213", score: 42 },
- { contractorId: "312", score: 60 },
- { contractorId: "313", score: 34 },
- ];
- const experienceInMaterialScores = [
- { contractorId: "321", score: 12 },
- { contractorId: "123", score: 32 },
- { contractorId: "313", score: 34 },
- { contractorId: "312", score: 60 },
- { contractorId: "213", score: 42 },
- ];
- matchmakingScores.push(
- ...demandLeadMatchmakingScores(locationScores, "LOCATION")
- );
- matchmakingScores.push(
- ...demandLeadMatchmakingScores(experienceInMaterialScores, "LOCATION")
- );
- console.dir(matchmakingScores, { depth: 4 });
- // Untitled-2.js
- /**
- *
- * @param {object[]} fieldScores
- * @param {string} fieldScores.contractorId
- * @param {number} fieldScores.score
- * @param {string} type
- * @param {[contractorId: string]: {type: string, score: number}[]} matchmakingScores
- */
- function demandLeadMatchmakingScores(fieldScores, type, matchmakingScores) {
- for (let fieldScore of fieldScores) {
- if (matchmakingScores[fieldScore.contractorId] === undefined) {
- matchmakingScores[fieldScore.contractorId] = [];
- }
- matchmakingScores[fieldScore.contractorId].push({
- score: fieldScore.score,
- type,
- });
- }
- }
- /**@type {{[contractorId: string]: {type: string, score: number}[]}[]} */
- const matchmakingScores = [];
- const locationScores = [
- { contractorId: "123", score: 32 },
- { contractorId: "321", score: 12 },
- { contractorId: "213", score: 42 },
- { contractorId: "312", score: 60 },
- { contractorId: "313", score: 34 },
- ];
- const experienceInMaterialScores = [
- { contractorId: "321", score: 12 },
- { contractorId: "123", score: 32 },
- { contractorId: "313", score: 34 },
- { contractorId: "312", score: 60 },
- { contractorId: "213", score: 42 },
- ];
- demandLeadMatchmakingScores(locationScores, "LOCATION", matchmakingScores);
- demandLeadMatchmakingScores(
- experienceInMaterialScores,
- "EX",
- matchmakingScores
- );
- console.dir(matchmakingScores, { depth: 4 });
- // Untitled-3.js
- const locationScores = [
- { contractorId: "123", score: 32 },
- { contractorId: "321", score: 12 },
- { contractorId: "213", score: 42 },
- { contractorId: "312", score: 60 },
- { contractorId: "313", score: 34 },
- ];
- const experienceInMaterialScores = [
- { contractorId: "321", score: 12 },
- { contractorId: "123", score: 32 },
- { contractorId: "313", score: 34 },
- { contractorId: "312", score: 60 },
- { contractorId: "213", score: 42 },
- ];
- matchmaking(
- "60ee8b06a312cd1ed6012136",
- locationScores.map(() => {})
- );
- /**
- *
- * @param {string} demandLeadId
- * @param {{type; string, score: number}[]} matchmakingScores
- */
- function matchmaking(demandLeadId, matchmakingScores) {}
- // Untitled-4.js
- const locationScores = [
- { contractorId: "123", score: 32 },
- { contractorId: "321", score: 12 },
- { contractorId: "213", score: 42 },
- { contractorId: "312", score: 60 },
- { contractorId: "313", score: 34 },
- ];
- const experienceInMaterialScores = [
- { contractorId: "321", score: 12 },
- { contractorId: "123", score: 32 },
- { contractorId: "313", score: 34 },
- { contractorId: "312", score: 60 },
- { contractorId: "213", score: 42 },
- ];
- contractorScores(...locationScores, ...experienceInMaterialScores);
- function contractorScores(...scores) {
- console.log(scores);
- for (let score of scores) {
- console.log(score.contractorId);
- }
- }
- // the final result
- const locationScores = [
- { contractorId: "123", score: 32 },
- { contractorId: "321", score: 12 },
- { contractorId: "213", score: 42 },
- { contractorId: "312", score: 60 },
- { contractorId: "313", score: 34 },
- ];
- const experienceInMaterialScores = [
- { contractorId: "321", score: 12 },
- { contractorId: "123", score: 32 },
- { contractorId: "313", score: 34 },
- { contractorId: "312", score: 60 },
- { contractorId: "213", score: 42 },
- ];
- const matchmakingScores = []
- matchmakingScores.push(create(locationScores, "loc", "123"), create(experienceInMaterialScores, 'ex', '123'));
- console.log(matchmakingScores);
- function create(scores, type, contractorId) {
- const score = scores.filter(score => score.contractorId === contractorId)[0].score;
- return {
- type,
- score,
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement