-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathrecommendations.js
More file actions
82 lines (66 loc) · 2.12 KB
/
Copy pathrecommendations.js
File metadata and controls
82 lines (66 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function normalizeTech(tech) {
return String(tech || "").trim().toLowerCase();
}
function isSameProject(projectA, projectB) {
if (!projectA || !projectB) return false;
if (projectA.projectNo != null && projectB.projectNo != null) {
return projectA.projectNo === projectB.projectNo;
}
if (projectA.day && projectB.day) {
return projectA.day === projectB.day;
}
if (projectA.projectName && projectB.projectName) {
return projectA.projectName === projectB.projectName;
}
if (projectA.name && projectB.name) {
return projectA.name === projectB.name;
}
return false;
}
export function getRecommendations(currentProject, allProjects) {
if (!currentProject || !Array.isArray(allProjects)) return [];
const currentTechStack = Array.isArray(currentProject.techStack)
? currentProject.techStack.map(normalizeTech)
: [];
const currentTechSet = new Set(currentTechStack);
return allProjects
.filter((project) => !isSameProject(project, currentProject))
.map((project) => {
let score = 0;
const projectTechStack = Array.isArray(project.techStack)
? project.techStack.map(normalizeTech)
: [];
// 🔥 1. Project type match (strong grouping signal)
if (
normalizeTech(project.projectType) ===
normalizeTech(currentProject.projectType)
) {
score += 5;
}
// 🔥 2. Tech stack overlap (MOST IMPORTANT)
const sharedTech = projectTechStack.filter((tech) =>
currentTechSet.has(tech),
);
score += sharedTech.length * 4;
// 🎯 3. Difficulty match (learning path consistency)
if (
normalizeTech(project.difficulty) ===
normalizeTech(currentProject.difficulty)
) {
score += 2;
}
// ⚡ 4. Small bonus: at least some tech match
if (sharedTech.length > 0) {
score += 1;
}
return {
...project,
score,
sharedTechCount: sharedTech.length,
};
})
.filter((project) => project.score > 0)
.sort((a, b) => b.score - a.score)
.slice(0, 3);
}
window.getRecommendations = getRecommendations;