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
bingoto be exposed to the outside world.We then define a helper function
belongsTowhich 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
integeris indeed part of theintegerListthanks to theList.memberfunction.Finally, we define our main function
bingowhich takes a list of integers. TheList.alltakes a function applied to each one of ourBINGOlist (which is just the integer representation of that word). If there is noBINGOinteger in theintegerList, it will return false.List.allexpects all applied functions to returnTrue. If only one of them returnFalse(meaning, one of theBINGOinteger has not been found in theintegerList), it will return false.Tests
Try it online.