-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPowerCode_AvoidObstacles.cs
57 lines (47 loc) · 1.96 KB
/
PowerCode_AvoidObstacles.cs
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Linq;
using System.Collections.Immutable;
using System.Collections.Generic;
namespace PowerCode_AvoidObstacles
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string inputArray = req.Query["inputArray"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
inputArray = inputArray ?? data?.inputArray;
int[] array = inputArray.Split(';').Select(n => Convert.ToInt32(n)).ToArray();
Array.Sort<int>(array, new Comparison<int>((i1, i2) => i1.CompareTo(i2)));
List<int> value = new List<int>();
for(int i=1; i <= array[array.Length - 1]; i++)
{
if (!array.Contains(i))
{
if (!value.Contains(i))
{
value.Add(i);
};
};
}
string message = string.Join(",", value.ToArray());
string responseMessage = string.IsNullOrEmpty(message)
? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
: $"The values are: {message}";
return new OkObjectResult(responseMessage);
}
}
}