Skip to content
Snippets Groups Projects
Commit 96428e77 authored by Yghore's avatar Yghore
Browse files

Minor changement

parent dc7ba7ed
No related branches found
No related tags found
No related merge requests found
Pipeline #10930 failed
...@@ -2,10 +2,84 @@ ...@@ -2,10 +2,84 @@
class Faker class Faker
{ {
private array $code = ['Filter a array and exclude element if key is "chapeau"', 'Check if word is a palindromic word', 'return a number of occurence for word into a text']; private array $code = ['
private array $test = ["If you're using JavaScript, you can use the filter method to exclude elements with a key of 'chapeau'. Here's an example:", public static int calculateSum(int[] nums) {
"A palindromic word is a word that reads the same backward as forward. To check if a word is a palindromic word, you can compare its reverse to the original word. Here's an example in JavaScript:", int sum = 0;
"To return the number of occurrences of a word in a text, you can use the split method to convert the text into an array of words, and then use the filter method to count the number of elements in the array that match the target word. Here's an example in JavaScript:"]; for (int num : nums) {
sum += num;
}
return sum;
}
',
'
public String[] filterArray(String[] array) {
// Create a new array to hold the filtered elements
List<String> filtered = new ArrayList<String>();
// Iterate over the input array and exclude elements with the key "chapeau"
for (String element : array) {
if (!"chapeau".equals(element)) {
filtered.add(element);
}
}
// Convert the filtered list back to an array
String[] result = new String[filtered.size()];
filtered.toArray(result);
return result;
',
'
public boolean isPalindrome(String word) {
// Convert the word to lowercase and remove non-alphanumeric characters
String cleanWord = word.toLowerCase().replaceAll("[^a-z0-9]", "");
// Compare the original word with its reversed version
String reversedWord = new StringBuilder(cleanWord).reverse().toString();
return cleanWord.equals(reversedWord);
}
'];
private array $test = ['
public void testIsPalindrome() {
String word1 = "racecar";
boolean expected1 = true;
boolean actual1 = isPalindrome(word1);
assertEqual(expected1, actual1);
String word2 = "hello";
boolean expected2 = false;
boolean actual2 = isPalindrome(word2);
assertEqual(expected2, actual2);
}
',
'
public void testFilterArray() {
String[] input1 = {"apple", "banana", "chapeau", "durian"};
String[] expected1 = {"apple", "banana", "durian"};
String[] actual1 = filterArray(input1);
assertArrayEqual(expected1, actual1);
String[] input2 = {"a", "b", "c", "d"};
String[] expected2 = {"b", "c"};
String[] actual2 = filterArray(input2);
assertArrayEqual(expected2, actual2);
}
',
'
public void testCalculateSum() {
int[] nums1 = {1, 2, 3, 4, 5};
int expected1 = 15;
int actual1 = calculateSum(nums1);
assertEqual(expected1, actual1);
int[] nums2 = {-1, 0, 1};
int expected2 = 0;
int actual2 = calculateSum(nums2);
assertEqual(expected2, actual2);
}
'];
public int $number; public int $number;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment