Skip to content

Commit

Permalink
Question 3 updated with 3 versions, tried apiVersion 58 to use String…
Browse files Browse the repository at this point in the history
….join w/o error.
  • Loading branch information
arieltahimik committed Mar 20, 2024
1 parent 2b4e75b commit 2c6a5ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions force-app/main/default/classes/ClassesObjectsMethods.cls
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public with sharing class ClassesObjectsMethods {
*/
public static String removeDuplicateWords(String sentence) {
List<String> words = new List<String>();
String s;

// Split the sentence into words
words = sentence.split(' ');
Expand All @@ -101,12 +102,22 @@ public with sharing class ClassesObjectsMethods {
uniqueWords.addAll(words);

// Join the unique words back into a sentence
words.clear();
words.addAll(uniqueWords);
sentence = String.join(words, ' ');

// Version 1
// words.clear();
// words.addAll(uniqueWords);
// s = String.join(words, ' ');

// Version 2
// Use Type Casting (Iterable<T>) and type cast uniqueWords SET
// s = String.join((Iterable<String>)uniqueWords, ' ');

// Version 3
// Update <apiVersion> to 58 and above
s = String.join(uniqueWords, ' ');

// Return the sentence with unique words
return sentence; // Replace null with the variable you used to store the result
return s;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>57.0</apiVersion>
<apiVersion>58.0</apiVersion>
<status>Active</status>
</ApexClass>

0 comments on commit 2c6a5ba

Please sign in to comment.