File extension is in extensions list
File extension is in extensions list
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
Given a file name and a list of extensions (including the dot), tell whether the file's extension is in the extensions list. The check should be case insensitive. The file might not have an extension.
Haskell
<lang Haskell> import Data.List import qualified Data.Char as Ch
toLower :: String -> String toLower = map Ch.toLower
isExt :: String -> [String] -> Bool isExt filename extensions = any (`elem` (tails . toLower $ filename)) $ map toLower extensions </lang>
Python
<lang Python> import os
def isExt(filename, extensions):
return os.path.splitext(filename.lower())[-1] in [e.lower() for e in extensions]
</lang>
Scala
<lang Scala> def isExt(fileName: String, extensions: List[String]): Boolean = {
extensions.map { _.toLowerCase }.exists { fileName.toLowerCase endsWith _ }
} </lang>