-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest1.js
More file actions
41 lines (32 loc) · 1.59 KB
/
test1.js
File metadata and controls
41 lines (32 loc) · 1.59 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
const query = 'awp asiimov';
const lowerQuery = query.toLowerCase();
const queryClean = lowerQuery.replace(/[^a-z0-9]/g, '');
const mockItems = [
{ name: 'AWP | Asiimov (Field-Tested)' },
{ name: 'StatTrak™ AWP | Asiimov (Field-Tested)' },
{ name: 'P90 | Trigon (Minimal Wear)' },
{ name: 'M4A4 | Asiimov (Field-Tested)' }
];
mockItems.sort((a, b) => b.name.length - a.name.length);
const matchedItem = mockItems.find(item => {
const nameLower = item.name.toLowerCase();
if (lowerQuery.includes(nameLower)) return true;
// Try omitting wear condition (e.g. "(Field-Tested)")
const baseName = nameLower.split('(')[0].trim();
if (baseName.length > 4 && lowerQuery.includes(baseName)) return true;
// Try without the pipe (e.g. "ak-47 redline")
const noPipe = baseName.replace('|', '').replace(/\s+/g, ' ').trim();
if (noPipe.length > 4 && lowerQuery.includes(noPipe)) return true;
// Try fully compressed (e.g. "ak47redline")
const compressedName = baseName.replace(/[^a-z0-9]/g, '');
if (compressedName.length > 4 && queryClean.includes(compressedName)) return true;
// 5. Check if query is fully contained within compressedName:
// User says "awp asiimov" -> "awpasiimov". Item is "AWP | Asiimov (Field-Tested)" -> "awpasiimovfieldtested".
// Does compressedName include queryClean?
if (queryClean.length > 4 && compressedName.includes(queryClean)) {
console.log('Matched via compressedName.includes:', compressedName, 'includes', queryClean);
return true;
}
return false;
});
console.log('Matched:', matchedItem?.name);