Created
March 17, 2023 16:10
-
-
Save barrybtw/a57f4280617500f9ad7336cf6715b0fc to your computer and use it in GitHub Desktop.
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
import { getCount_IndexOf } from "./indexof.ts"; | |
import { getCount_Set } from "./set.ts"; | |
const input = | |
"hello world i am very big string maybe with vowel maybe not with wovel...."; | |
// Performance test each function 1000000 times | |
const start_IndexOf = Date.now(); | |
for (let i = 0; i < 1000000; i++) { | |
getCount_IndexOf(input); | |
} | |
const end_IndexOf = Date.now(); | |
console.log(`indexOf: ${end_IndexOf - start_IndexOf}ms`); | |
const start_Set = Date.now(); | |
for (let i = 0; i < 1000000; i++) { | |
getCount_Set(input); | |
} | |
const end_Set = Date.now(); | |
console.log(`set: ${end_Set - start_Set}ms`); |
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
const vowels = ["a", "e", "i", "o", "u"]; | |
export function getCount_IndexOf(arg: string): number { | |
const list = arg.split(""); | |
let result = 0; | |
for (let index = 0, { length } = list; index < length; ++index) { | |
if (vowels.indexOf(list[index]) != -1) ++result; | |
} | |
return result; | |
} |
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
const vowels = new Set(["a", "e", "i", "o", "u"]); | |
export function getCount_Set(arg: string): number { | |
const list = arg.split(""); | |
let result = 0; | |
for (let i = 0; i < list.length; i++) { | |
if (vowels.has(list[i])) ++result; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment