Created
April 5, 2020 01:52
-
-
Save Nicknyr/81d111b4e2a587235eaf35b38b988254 to your computer and use it in GitHub Desktop.
CodeSignal - Find Email Domain
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
| /* | |
| An email address such as "[email protected]" is made up of a local part ("John.Smith"), an "@" symbol, then a domain part ("example.com"). | |
| The domain name part of an email address may only consist of letters, digits, hyphens and dots. The local part, however, also allows a lot of different special characters. Here you can look at several examples of correct and incorrect email addresses. | |
| Given a valid email address, find its domain part. | |
| Example | |
| For address = "[email protected]", the output should be | |
| findEmailDomain(address) = "example.com"; | |
| For address = "[email protected]", the output should be | |
| findEmailDomain(address) = "codesignal.com". | |
| */ | |
| function findEmailDomain(address) { | |
| // Turn address string into an array | |
| let email = address.split(""); | |
| let end; | |
| // Loop through array of characters until we find @, then slice everything after the @ | |
| for(let i = 0; i < email.length; i++) { | |
| if(email[i] === '@') { | |
| end = email.slice(i + 1); | |
| } | |
| } | |
| // Expects a string for the answer, turn end back into a string | |
| let answer = end.join(''); | |
| return answer; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment