Last active
April 4, 2024 08:38
-
-
Save pgajek2/e2d77e76b26b8ffbc6051cd41a8b47d3 to your computer and use it in GitHub Desktop.
BeyondTheCloud: Code Challenge 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // JAVA SCRIPT | |
| // Problem | |
| function build(productA, productB, productC) { | |
| let result = ''; | |
| if (productA) { | |
| result += productA; | |
| if (productB) { | |
| result += productB; | |
| if (productC) { | |
| result += productC; | |
| } | |
| } | |
| } | |
| return result; | |
| } | |
| // Your code | |
| // function build(...) { | |
| // Your code here | |
| // } | |
| // Test 1 | |
| console.assert('ABC' === build('A', 'B', 'C')); | |
| // Test 2 | |
| console.assert('AB' === build('A','B','')); | |
| // Test 3 | |
| console.assert('A' === build('A','','C')); | |
| // Test 4 | |
| console.assert('' === build('','B','C')); | |
| // APEX | |
| public class CodeChallenge { | |
| public String build(String productA, String productB, String productC) { | |
| String result = ''; | |
| if (String.isNotBlank(productA)) { | |
| result += productA; | |
| if (String.isNotBlank(productB)) { | |
| result += productB; | |
| if (String.isNotBlank(productC)) { | |
| result += productC; | |
| } | |
| } | |
| } | |
| return result; | |
| } | |
| } | |
| // Your code | |
| // public class CodeChallenge { | |
| // public String build(String productA, String productB, String productC) { | |
| // // Your code here | |
| // } | |
| // } | |
| // Test 1 | |
| Assert.isTrue('ABC' == new CodeChallenge().build('A', 'B', 'C')); | |
| // Test 2 | |
| Assert.isTrue('AB' == new CodeChallenge().build('A','B','')); | |
| // Test 3 | |
| Assert.isTrue('A' == new CodeChallenge().build('A','','C')); | |
| // Test 4 | |
| Assert.isTrue('' == new CodeChallenge().build('','B','C')); |
// JAVA SCRIPT
function build(...args) {
let result = "";
for (let product of args) {
if (product === "") return result;
result += product;
}
return result;
}
// Test 1
console.assert("ABC" === build("A", "B", "C"));
// Test 2
console.assert("AB" === build("A", "B", ""));
// Test 3
console.assert("A" === build("A", "", "C"));
// Test 4
console.assert("" === build("", "B", "C"));
// APEX
public class CodeChallenge {
public String build(String productA, String productB, String productC) {
String result = '';
for (String product : new List<String>{productA, productB, productC}) {
if (String.isBlank(product)) return result;
result += product;
}
return result;
}
}
// Test 1
Assert.isTrue('ABC' == new CodeChallenge().build('A', 'B', 'C'));
// Test 2
Assert.isTrue('AB' == new CodeChallenge().build('A', 'B', ''));
// Test 3
Assert.isTrue('A' == new CodeChallenge().build('A', '', 'C'));
// Test 4
Assert.isTrue('' == new CodeChallenge().build('', 'B', 'C'));
Author
// JAVA SCRIPT function build(...args) { let result = ""; for (let product of args) { if (product === "") return result; result += product; } return result; } // Test 1 console.assert("ABC" === build("A", "B", "C")); // Test 2 console.assert("AB" === build("A", "B", "")); // Test 3 console.assert("A" === build("A", "", "C")); // Test 4 console.assert("" === build("", "B", "C")); // APEX public class CodeChallenge { public String build(String productA, String productB, String productC) { String result = ''; for (String product : new List<String>{productA, productB, productC}) { if (String.isBlank(product)) return result; result += product; } return result; } } // Test 1 Assert.isTrue('ABC' == new CodeChallenge().build('A', 'B', 'C')); // Test 2 Assert.isTrue('AB' == new CodeChallenge().build('A', 'B', '')); // Test 3 Assert.isTrue('A' == new CodeChallenge().build('A', '', 'C')); // Test 4 Assert.isTrue('' == new CodeChallenge().build('', 'B', 'C'));
I like that @Damecek !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is it simpler? :)