-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.php
34 lines (29 loc) · 1002 Bytes
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
$challenges = [
'addition' => [
'description' => 'Create a function which could return the sum of two numbers.',
'test_cases' => [
['arguments' => [15, 17], 'result' => 32],
['arguments' => [-87, 87], 'result' => 0],
['arguments' => [0.00001, 0.00002], 'result' => 0.00003],
],
],
];
if (!isset($_GET['challenge'])) {
header('Content-Type: application/json');
echo json_encode($challenges);
return;
}
$challenge = $challenges[$_GET['challenge']];
foreach ($challenge['test_cases'] as $testCase) {
// todo: run JS code and check if test case passes
$result = null;
if ($result !== $testCase['result']) {
http_response_code(400);
header('Content-Type: application/json');
echo json_encode(['error' => sprintf('Expected %s but got %s', $testCase['result'], $result)]);
return;
}
}
header('Content-Type: application/json');
echo json_encode(['status' => 'success']);