You need to sign in to do that
Don't have an account?
fiona gentry
How to use collection
I have a interview question below
GIVEN: a string of characters,
WHEN: reverse method is invoked
THEN: return an array of characters in reversed order for alphanumeric characters only however all other non-alphanumeric characters need to retain their original position
- Implement solution in Apex
Regards,
Fiona
GIVEN: a string of characters,
WHEN: reverse method is invoked
THEN: return an array of characters in reversed order for alphanumeric characters only however all other non-alphanumeric characters need to retain their original position
- Implement solution in Apex
public class Class { /* PROBLEM: - User Story: As an organizer, I need to sort in reverse order, so that I can help those at the end of the line. - Acceptance Criteria: GIVEN: a string of characters, WHEN: reverse method is invoked THEN: return an array of characters in reversed order for alphanumeric characters only however all other non-alphanumeric characters need to retain their original position - Implement solution in Apex VALIDATE SOLUTION: // Run anonymous apex ASSESSMENT_UtilityClass2.validateSolution(); */ // SAMPLE: // 1. input: 'ABC@HI#J2' // output: ['2','J','I','@','H','C','#','B','A'] public static List<String> reverseSpecialString(String input) { List<String> resultList = new List<String>(); // IMPLEMENT resultList = input.split(''); string reversedString=''; for(integer i=resultList.size()-1;i>=0;i--) { resultList[i]=reversedString+resultList[i]; } return resultList; } public static void validateSolution() { String input = 'ABC@HI#J2'; List<String> expected = new List<String> {'2','J','I','@','H','C','#','B','A'}; List<String> actual = reverseSpecialString(input); System.assertEquals(expected, actual, 'Invalid Results'); } }can any one help solve above for me ,need to validate the code in anonymus apex by writing
Class.validateSolution();
Regards,
Fiona
Where exactly are you stuck?