DEV Community

loading...

Different Types of Functions

keepoSteepo
・1 min read

Contain functions are functions that are made from scratch, per se. These are function in which every component in the function is defined to achieve a desired outcome. The hasPrefix and hasSuffix functions are built in functions for a certain type, which just so happens to be type String. They are functions that do not have to be created from scratch every time, they were pre built into the type.

A problem that is sure to be encountered if the user inputs uppercase or lowercase is when a function is tied to certain case. The function might be able to take any input in that starts with a certain value, but if it is tied to a certain case it will not return the desired outcome.
Fear not, there is a fix for this. Instead of writing a function for each possible case, one might change the case of the text before trying to match it using the lowercased method.

let lowerQuestion = question.lowercased()
lowerQuestion.hasPrefix(“where”)>

Discussion (0)