Skip to content

Instantly share code, notes, and snippets.

@jurosh
Created December 30, 2022 20:57
Show Gist options
  • Save jurosh/35cc90303989fbeb9bdbc90a11f59969 to your computer and use it in GitHub Desktop.
Save jurosh/35cc90303989fbeb9bdbc90a11f59969 to your computer and use it in GitHub Desktop.
const vowels = 'aeiou';
function sol1(str) {
return str
.split('')
.filter((letter) => !vowels.includes(letter.toLowerCase()))
.join('');
}
function sol2(str) {
return str.replace(/[aeiou]/gi, '');
}
const text = `
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing.`;
const repeat = 5000;
let sol1result, sol2result;
console.time('sol1');
for (let i = 1; i < repeat; i++) {
sol1result = sol1(text);
}
console.timeEnd('sol1');
console.time('sol2');
for (let i = 1; i < repeat; i++) {
sol2result = sol2(text);
}
console.timeEnd('sol2');
console.log(sol1result === sol2result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment