Compare commits
2 Commits
d1fc53206c
...
9de5ddcfbf
Author | SHA1 | Date | |
---|---|---|---|
9de5ddcfbf | |||
474345a204 |
@ -9,9 +9,9 @@
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"devDependencies": {
|
||||
"sass": "^1.85.0",
|
||||
"sass": "^1.85.1",
|
||||
"typescript": "^5.7.3",
|
||||
"vite": "^6.1.1",
|
||||
"vite": "^6.2.0",
|
||||
"vite-plugin-html": "^3.2.2"
|
||||
}
|
||||
}
|
33
src/rt/shell/fs/search.ts
Normal file
33
src/rt/shell/fs/search.ts
Normal file
@ -0,0 +1,33 @@
|
||||
interface Search {
|
||||
binary: <T>(list: T[], find: T) => T | undefined,
|
||||
linear: <T>(list: T[], find: T) => T | undefined,
|
||||
}
|
||||
const search = {} as Search
|
||||
|
||||
search.binary = function(list, find) {
|
||||
list.sort()
|
||||
let start = 0
|
||||
let end = list.length-1
|
||||
while (start<=end) {
|
||||
const median = (start+end)>>1
|
||||
if (list[median] === find) {
|
||||
return find
|
||||
} else if (list[median]<find) {
|
||||
start = median+1
|
||||
} else {
|
||||
end = median-1
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
search.linear = function(list, find) {
|
||||
for (const item of list) {
|
||||
if (item === find) {
|
||||
return item
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
export default search
|
Loading…
x
Reference in New Issue
Block a user