Day 4: Haskell

TLDR : Failing Spectacularly

  1. Create a function elem that returns True if an element is in a list and False if it isn’t.
el xs a
| xs == [] = False
| otherwise = if (head xs) == a then True else el (tail xs) a
elem _ [] = False
elem e (x:xs) = (e == x) || (elem e xs)
-- Problem 2
nub1 xs
| xs == [] = []
| otherwise = if elem (head xs) (tail xs) then nub1 tail xs else ......
Tried something like this too
nub1 xs = [head xs | x <- xs , el1 (head xs) (tail xs)]
nub2 [] = []nub2 (x:xs)
| elem x xs = nub2 xs
| otherwise = x:(nub2 xs)
-- Problem 3isAsc [] = True
isAsc (x:xs)
| x >= (head xs) = isAsc xs
| x < (head xs) = False
isAsc [] = True
isAsc [x] = True
isAsc (x:y:xs) = (x <= y) && isAsc (y:xs)

--

--

I do stuff. Like stuff about policy. And book stuff. And gaming stuff. And stuff about life. And stuff about stuff.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store