OlexG / Patterns

Simples demos of various design patterns in javascript and typescript.
0 stars 0 forks source link

Use toLowerCase for checking for inclusion of strings #1

Closed mattfbacon closed 3 years ago

mattfbacon commented 3 years ago
function isWelcomeMessage(message : string) {
    return (message.includes('welcome') || message.includes('Welcome'));
}

can be replaced with

function isWelcomeMessage(message : string) {
    return message.toLowerCase().includes('welcome');
}

(And of course this can be an arrow function but that's up to you.)

mattfbacon commented 3 years ago

This applies to Behavioral/chainOfResponsibility.ts

OlexG commented 3 years ago

but what if I don't want wElCoMe to be considered a welcome message >:)

mattfbacon commented 3 years ago

/^[wW]elcome/.test(message)