-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use client"; | ||
import { | ||
tool | ||
} from "../tools/info"; | ||
import { | ||
not | ||
} from '../components/TransferList'; | ||
const generateTries = (mostUsed: string, realTools: tool[]) => { | ||
const unUsed = not(realTools.map(single => single.to), Object.keys(JSON.parse(mostUsed))).slice(0, 3), isUnFull = unUsed.length < 3, // 判断没用过的工具有没有三个 | ||
toFill = (Object.entries(JSON.parse(mostUsed)) as [string, number][]).sort((r, g) => { | ||
if (r[1] < g[1]) { | ||
return -1; | ||
} if (r[1] > g[1]) { | ||
return 1; | ||
} | ||
return 0; | ||
}).map(single => single[0]).slice(0, 3 - unUsed.length); // 如果没用过的工具连三个都没有,那么就从使用最少的工具里选几个 | ||
return (isUnFull ? unUsed : unUsed.concat(toFill)).map(to => { | ||
var tool: tool; | ||
realTools.forEach(single => { | ||
if (single.to === to) { | ||
tool = single; | ||
} | ||
}); | ||
return tool; | ||
}); | ||
}; | ||
export default generateTries; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters