You need to create a function, helloWorld, that will return the String Hello, World! without actually using raw strings. This includes quotes, double quotes and template strings. You can, however, use the String constructor and any related functions.
You cannot use the following:
"Hello, World!"
'Hello, World!'
`Hello, World!`
Good luck and try to be as creative as possible!
import "package:test/test.dart";
import "package:solution/solution.dart";
import "dart:io";
void main() {
group("Hello World Without strings", () {
String userCode = new File("/workspace/solution.txt").readAsStringSync();
test("Doesn't use double quotes", () {
expect(userCode.contains('"'), equals(false));
});
test("Doesn't use single quotes", () {
expect(userCode.contains("'"), equals(false));
});
test("Returns 'Hello, World!'", () {
expect(helloWorld(), equals('Hello, World!'));
});
});
}
내 정답
String helloWorld() => String.fromCharCodes([72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33]);
String helloWorld() {
var h = String.fromCharCode(72);
var e = String.fromCharCode(101);
var l1 = String.fromCharCode(108);
var l2 = String.fromCharCode(108);
var o = String.fromCharCode(111);
var comma = String.fromCharCode(44);
var space = String.fromCharCode(32);
var w = String.fromCharCode(87);
var r = String.fromCharCode(114);
var d = String.fromCharCode(100);
var exclamation = String.fromCharCode(33);
var total = h+e+l1+l2+o+comma+space+w+o+r+l1+d+exclamation;
return total;