-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature fix to lower case set list conversion issue (#3)
* Changed all refs to Set and update challenge wording * null check * fix the fix --------- Co-authored-by: Saman Attar <[email protected]>
- Loading branch information
1 parent
56abdbf
commit d0e4ccf
Showing
3 changed files
with
14 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ System.debug(normalizedEmail); // Outputs: '[email protected]' | |
--- | ||
### Challenge: Using `toLowerCase()` for Email Deduplication | ||
|
||
You are tasked with cleaning up a set of email addresses in a Salesforce application. Due to various input methods and user errors, the set might contain emails with different case formats. Using `toLowerCase()`, you can standardize all email addresses to lowercase. | ||
You are tasked with cleaning up a list of email addresses in a Salesforce application. Due to various input methods and user errors, the list might contain duplicate emails with different case formats. Using `toLowerCase()`, you can standardize all email addresses to lowercase to help identify and remove duplicates. | ||
|
||
**Your task:** | ||
Write code that processes a set of email strings and converts each to lowercase. | ||
Write code that processes a list of email strings, converts each to lowercase, and then deduplicates the list. You will start with a predefined list of emails that includes potential duplicates with varying cases. Your method should return a set of strings. |
11 changes: 6 additions & 5 deletions
11
force-app/main/default/apexdeepdive/string/toLowerCase/ToLowerCaseSolution.cls
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
public class ToLowerCaseSolution { | ||
public Set<String> standardizeEmails(Set<String> emails) { | ||
public class StringUtils { | ||
public Set<String> standardizeEmails(List<String> emails) { | ||
Set<String> uniqueEmails = new Set<String>(); | ||
for (String email : emails) { | ||
email.toLowerCase(); | ||
uniqueEmails.add(email.toLowerCase()); | ||
} | ||
return emails; | ||
return uniqueEmails; | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,10 +28,11 @@ public with sharing class ToLowerCaseTest { | |
} | ||
|
||
public TestResult test1(String testNum) { | ||
Set<String> emailsInput = new Set<String>{ | ||
List<String> emailsInput = new List<String>{ | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]' | ||
'[email protected]', | ||
'[email protected]' | ||
}; | ||
String testDesc = formatEmailSet(emailsInput); | ||
|
||
|
@@ -45,7 +46,7 @@ public with sharing class ToLowerCaseTest { | |
try { | ||
Set<String> result = su.standardizeEmails(emailsInput); | ||
|
||
if(!emailsSolution.containsAll(result)){ | ||
if(result == null || !emailsSolution.containsAll(result)){ | ||
msg = | ||
'Expected ' + | ||
emailsSolution + | ||
|
@@ -60,7 +61,7 @@ public with sharing class ToLowerCaseTest { | |
} | ||
|
||
public TestResult test2(String testNum) { | ||
Set<String> emailsInput = new Set<String>{ | ||
List<String> emailsInput = new List<String>{ | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]' | ||
|
@@ -76,7 +77,7 @@ public with sharing class ToLowerCaseTest { | |
try { | ||
Set<String> result = su.standardizeEmails(emailsInput); | ||
|
||
if(!emailsSolution.containsAll(result)){ | ||
if(result == null || !emailsSolution.containsAll(result)){ | ||
msg = | ||
'Expected ' + | ||
emailsSolution + | ||
|