We then define a helper function belongsTo which will not be exposed to the outside world.
It takes two parameters: the first being a list (array) of integers, and the second is an integer. The function will then return a boolean indicating if the integer is indeed part of the integerList thanks to the List.member function.
Finally, we define our main function bingo which takes a list of integers. The List.all takes a function applied to each one of our BINGO list (which is just the integer representation of that word). If there is no BINGO integer in the integerList, it will return false. List.all expects all applied functions to return True. If only one of them return False (meaning, one of the BINGO integer has not been found in the integerList), it will return false.
Tests
moduleBingoTestexposing(suite)importBingoexposing(bingo)importExpectexposing(equal)importTestexposing(Test,describe,test)suite:Testsuite=describe"Basic tests"[test"It should return true when passing a valid array"<|\_->equalTrue<|bingo[21,13,2,7,5,14,7,15,9,10],test"It should return false when passing an invalid array"<|\_->equalFalse<|bingo[1,2,3,4,5,6,7,8,9,10]]
Elm
Eplainations
Here we say that we only want the function
bingo
to be exposed to the outside world.We then define a helper function
belongsTo
which will not be exposed to the outside world.It takes two parameters: the first being a list (array) of integers, and the second is an integer. The function will then return a boolean indicating if the
integer
is indeed part of theintegerList
thanks to theList.member
function.Finally, we define our main function
bingo
which takes a list of integers. TheList.all
takes a function applied to each one of ourBINGO
list (which is just the integer representation of that word). If there is noBINGO
integer in theintegerList
, it will return false.List.all
expects all applied functions to returnTrue
. If only one of them returnFalse
(meaning, one of theBINGO
integer has not been found in theintegerList
), it will return false.Tests
Try it online.