Compare commits

...

2 Commits

Author SHA1 Message Date
9de5ddcfbf update deps 2025-02-25 18:32:16 -05:00
474345a204 search module for fs 2025-02-25 18:32:08 -05:00
2 changed files with 35 additions and 2 deletions

View File

@ -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
View 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