Avatar of kisfaludi89

kisfaludi89's solution

to Reverse String in the C# Track

Published at Apr 18 2019 · 0 comments
Instructions
Test suite
Solution

Reverse a string

For example: input: "cool" output: "looc"

Running the tests

To run the tests, run the command dotnet test from within the exercise directory.

Initially, only the first test will be enabled. This is to encourage you to solve the exercise one step at a time. Once you get the first test passing, remove the Skip property from the next test and work on getting that test passing. Once none of the tests are skipped and they are all passing, you can submit your solution using exercism submit ReverseString.cs

Further information

For more detailed information about the C# track, including how to get help if you're having trouble, please visit the exercism.io C# language page.

Source

Introductory challenge to reverse an input string https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb

ReverseStringTest.cs

// This file was auto-generated based on version 1.1.0 of the canonical data.

using Xunit;

public class ReverseStringTest
{
    [Fact]
    public void An_empty_string()
    {
        Assert.Equal("", ReverseString.Reverse(""));
    }

    [Fact(Skip = "Remove to run test")]
    public void A_word()
    {
        Assert.Equal("tobor", ReverseString.Reverse("robot"));
    }

    [Fact(Skip = "Remove to run test")]
    public void A_capitalized_word()
    {
        Assert.Equal("nemaR", ReverseString.Reverse("Ramen"));
    }

    [Fact(Skip = "Remove to run test")]
    public void A_sentence_with_punctuation()
    {
        Assert.Equal("!yrgnuh m'I", ReverseString.Reverse("I'm hungry!"));
    }

    [Fact(Skip = "Remove to run test")]
    public void A_palindrome()
    {
        Assert.Equal("racecar", ReverseString.Reverse("racecar"));
    }
}
using System;

public static class ReverseString
{
    public static string Reverse(string input)
    {
        //throw new NotImplementedException("You need to implement this function.");
        char[] charArray = input.ToCharArray();
        Array.Reverse(charArray);
        return new string(charArray);
    }
}

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?