Skip to content

Commit

Permalink
Question 5 solution (findTheScientist)
Browse files Browse the repository at this point in the history
  • Loading branch information
arieltahimik committed Mar 19, 2024
1 parent fd773ad commit 2b4e75b
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions force-app/main/default/classes/ClassesObjectsMethods.cls
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,18 @@ public with sharing class ClassesObjectsMethods {
List<String> scientistNames = new List<String>{'Tim Berners-Lee', 'Alan Turing', 'Grace Hopper', 'Donald Knuth', 'Guido van Rossum', 'Ken Thompson', 'Stephen Hawking'};

// The variable to store the concatenated string

// Loop through the list of scientists' names

// If the name doesn't contain the letter 'G', skip this iteration

// Add the name to the result string, followed by a comma

// Remove the last comma from the result string

return null; // Replace null with the variable you used to store the result
String result='';

// Loop through the list of scientists' names
for (Integer i=0; i<scientistNames.size(); i++) {
if(scientistNames[i].toLowerCase().contains('g')) {
result += scientistNames[i];
if (i != (scientistNames.size()-1)) {
result += ',';
}
}
}
return result;
}

/**
Expand Down

0 comments on commit 2b4e75b

Please sign in to comment.