r/badcode •

[deleted by user]

[deleted] — view deleted post

0 Upvotes

41 comments sorted by

View all comments

4

u/rcmaehl Jun 05 '19 edited Jun 17 '19

Not really that bad of code, just *clever* code.

* Compares the LENGTH of the numbers instead of the value of the numbers.

* Returns incorrectly if the first value was the highest or lowest

* Only works for numbers under 1 million

* Requires a negative number to work

* Unhelpful Error messages

Func high_and_low($s)

	$l = 0
	$h = 0

	Do
		If Not StringInStr($s, ",") Then
			$p = $s
		Else
			$p = StringLeft($s, 1)
			If StringRight($p, 1) = "," Then
				MsgBox(0, "OOPSIE WOOPSIE!!", "Uwu We made a fucky wucky!! A wittle fucko boingo! The code monkeys at our headquarters are working VEWY HAWD to fix this!")
			Else
				$p = StringLeft($s, 2)
				If StringRight($p, 1) = "," Then
					$s = StringRight($s, StringLen($s) - 2)
					$p = StringLeft($p, 1)
				Else
					$p = StringLeft($s, 3)
					If StringRight($p, 1) = "," Then
						$s = StringRight($s, StringLen($s) - 3)
						$p = StringLeft($p, 2)
					Else
						$p = StringLeft($s, 4)
						If StringRight($p, 1) = "," Then
							$s = StringRight($s, StringLen($s) - 4)
							$p = StringLeft($p, 3)
						Else
							$p = StringLeft($s, 5)
							If StringRight($p, 1) = "," Then
								$s = StringRight($s, StringLen($s) - 5)
								$p = StringLeft($p, 4)
							Else
								$p = StringLeft($s, 6)
								If StringRight($p, 1) = "," Then
									$s = StringRight($s, StringLen($s) - 6)
									$p = StringLeft($p, 5)
								Else
									$p = StringLeft($s, 7)
									If StringRight($p, 1) = "," Then
										$s = StringRight($s, StringLen($s) - 7)
										$p = StringLeft($p, 6)
									Else
										MsgBox(0, "OOPSIE WOOPSIE!!", "Uwu We made a fucky wucky!! A wittle fucko boingo! The code monkeys at our headquarters are working VEWY HAWD to fix this!")
									EndIf
								EndIf
							EndIf
						EndIf
					EndIf
				EndIf
			EndIf
		EndIf

		If StringLen(String(Number(10^$p))) > StringLen(String(Number(10^$h))) Then
			If StringLeft(String(Number(10^$p)), 1) = 0 Then ; Negative Number
				;;;
			Else
				$h = $p
			EndIf
		EndIf

		If StringLen(String(Number(10^$p))) > StringLen(String(Number(10^$l))) Then
			If StringLeft(String(Number(10^$p)), 1) = 0 Then ; Negative Number
				$l = $p
			Else
				;;;
			EndIf
		EndIf

	Until $p = $s
	
	Return $l & ", " & $h

EndFunc