Skip to content

Commit

Permalink
Feature fix to lower case set list conversion issue (#3)
Browse files Browse the repository at this point in the history
* Changed all refs to Set and update challenge wording

* null check

* fix the fix

---------

Co-authored-by: Saman Attar <[email protected]>
  • Loading branch information
walters954 and SamanAttar authored May 30, 2024
1 parent 56abdbf commit d0e4ccf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 +
Expand All @@ -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]'
Expand All @@ -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 +
Expand Down

0 comments on commit d0e4ccf

Please sign in to comment.