Last active
June 25, 2024 04:29
-
-
Save hrishikeshs/ceac10698471cb3aa8cc16ab3a378d70 to your computer and use it in GitHub Desktop.
abstraction-primitives
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type DateOfBirth = { | |
day: number; | |
month: number; | |
year: number; | |
}; | |
export type User = { | |
firstName: string | undefined; | |
lastName: string | undefined; | |
dateOfBirth: DateOfBirth | undefined; | |
license: number | undefined; | |
planType: 'free' | 'premium' | 'pro'; | |
numAccounts: number; | |
}; | |
const createUser = () => { | |
const user = { | |
firstName: undefined, | |
lastName: undefined, | |
dateOfBirth: undefined, | |
license: undefined, | |
planType: 'free', | |
numAccounts: 1 | |
}; | |
const setName = (firstName, lastName) => { | |
user.firstName = firstName; | |
user.lastName = lastName; | |
} | |
/* ... other setters */ | |
const getName = () => { | |
const { firstName, lastName } = user; | |
return { firstName, lastName}; | |
} | |
/* ... other getters */ | |
const getUserDetails = () => { | |
return Object.freeze({...user}); | |
} | |
return Object.freeze({ | |
getName, | |
setName, | |
getUserDetails | |
}); | |
}; | |
const isUserEligibleForLicense = (user: User) => { | |
// write code here that checks if the user's age is >= 16 | |
} | |
const isPremiumUser = (user: User) => { | |
// write code here that checks if the user's plantype is premium; | |
} | |
const isProUser = (user: User) => { | |
// write code here that checks if the user's plantype is 'pro'; | |
} | |
const isFreeUser = (user: User) => { | |
// write code here that checks if the user's plantype is 'free'; | |
} | |
... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment