Last active
August 29, 2015 14:05
-
-
Save ItsSpyce/22167d402ebabaffcb2f to your computer and use it in GitHub Desktop.
PEOPLE WANT ME TO TYPE QUIETER.
This file contains 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
//HOPEFULLY this will allow for you to put something in like "5..10" and have the returning array | |
//replicate the Ruby method of int..int to get all methods in between. Sadly, the ints will have to be a string variable. | |
//EX: | |
//"2..12".GetInts(); will return [3,4,5,6,7,8,9,10,11] while (Gets all ints in between) | |
//"2...12".GetInts(); will return [2,3,4,5,6,7,8,9,10,11,12]. (Gets all ints in between INCLUDING BARRIERS) | |
//To be quite honest, the only reason for writing this is so that I can get all numbers in between for the simplicity. | |
//I'm really just fucking sick of the fact that .NET doesn't have the int implementations and should REALLY | |
//work on making their shit just work for once. If you see something another language implements, TRY TAKING A FCKING HINT AND | |
//USE IT TOO. | |
public static int[] GetInts(this string input){ | |
var incl = false; | |
if (!input.Contains("..")) throw new InvalidParametersException("Must have a valid input!"); | |
if (input.Contains("...")) incl = true; | |
int floor; | |
int ceiling; | |
var min = int.Parse(input.Split(!incl ? ".." : "...")[0]); | |
var max = int.Parse(input.Split(!incl ? ".." : "...")[1]); | |
if (!incl){ | |
min++; | |
max--; | |
} | |
var i = min; | |
var cache = new int[] {}; | |
while(min <= i && i <= max){ | |
cache.Concat(new []{i}); | |
} | |
return cache; | |
} | |
//P.S. I'm doing this out of boredom in class because United States Marine Corps is taking my | |
//time to learn how to fix electronics. Gah. I have a counseling appopintment at 3 and it really can't get here | |
//fast enough. I'm not mental, I'm just slightly unstable as we speak. Sometimes I just wonder if I can go through | |
// this shit and question myself as to how I don't just quit ._. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment