LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

🅱️ode 🅱️ritique

Root / General / [.]

📌
YolkaiCreated:
This doesnt return a string which could cause an error. Allow me to improve that for you.
DEF RND$()
 RETURN FORMAT$("%D",RNDF())
END

The last answer returned a string which might have numbers in it, which might cause erroneous behavior if the caller does not expect numbers in a string. Allow me to improve that for you. Edit: I messed up!
DEF RNDWOD$()
 VAR S$ = FORMAT$("%F",RNDF())
 VAR I = 0, C$
 WHILE I < LEN(S$)
  C$ = S$[I]
  'remove char if it is a digit
  IF C$>="0"&&C$<="9" THEN S$[I]="" ELSE INC I,1
 WEND
 RETURN S$
END

VAR PI$=STR$(PI())
VAR I

'Returns the next digit of pi when called
DEF RND$()
 INC I
 I=I%LENGTH(PI$) 'make sure the index doesn't exceed the length of PI$
 RETURN PI$[I]
END

'get the length of a string
DEF LENGTH S$
 VAR I
 WHILE MID$(S$,I,1)!="" 'MID$ returns an empty string when out of range
  INC I
 WEND
 RETURN I
END

Does it have to be Smile🅱️asic code?

nah just get a random string like this:
DEF RNDS()
   RETURN INPUT
END
or Lua: local a = "" function rndString(_len) for i = 1, math.random(_len) do a..string.char(math.random(255)) end return a end

nah just get a random string like this:
DEF RNDS()
   RETURN INPUT
END
That doesn't even work

nah just get a random string like this:
DEF RNDS()
   RETURN INPUT
END
That doesn't even work
the idea does?

this is 🅱️ode 🅱️ritique, not 🅱️idea 🅱️ritique

this is 🅱️ode 🅱️ritique, not 🅱️idea 🅱️ritique
English with emotes isn't a programming language

Can someone please help improve my sorting function? It's too slow...
DEF SORT_ARRAY  (ARRAY[] )
DIM NEW [0]
FOR J = 0 TO LEN(ARRAY) -1
   FOR I=0 TO LEN(ARRAY) - 1
      IF ARRAY[I] == MIN(ARRAY) THEN
         PUSH NEW, ARRAY[I]
         ARRAY[ I] = MAX( ARRAY )
         BREAK
      ENDIF
   NEXT
NEXT
RETURN  NEW
END

'sort an array, javascript style, with some lewd easter eggs
DEF jsSort(A[])
  DIM N$[0], E$
  WHILE LEN(A)
    'valentine's day edition <3
    IF (A[0]||0)<3 THEN 
      PUSH N$,STR$(POP(A))
    ELSE 
      PUSH N$,POP(A)
    ENDIF
   
    'valentine's day edition OWO
    FOR I = LEN(N) -1 TO 1 STEP -1
      IF N$[I] <= N$[I-1] THEN
        SWAP N$[I], N$[I-1]
      ELSE
        BREAK
      ENDIF
    NEXT

  WEND
  RETURN N$
END

'please dont use 0.00199
DEF NORT(INP[])
 DIM RET[LEN(INP)],RES,W,V
 FILL RET,0.00199
 FOR I=0 TO LEN(INP)-1
  RES=0
  W=INP[I]
  FOR _I=0 TO LEN(INP)-1
   V=INP[_I]
   INC RES,ABS(0.5+ABS(W-V)/(2*(W-V))*(W-V)/(W-V))
  NEXT
  IF RET[RES]==INP[I] THEN
   REPEAT
    INC RES
   UNTIL RET[RES] != INP[I]
  ENDIF
  RET[RES]=INP[I]
 NEXT
 RETURN RET
END

Hi! I forgot math exists and only know how to use functions. Is there a simpler way to see if a numerical value is negative, other than using the complicated
<0
and the too-convenient
SGN( )
function?

IF value+(""*@_||!.) <3 THEN ...
IF value>>value THEN ...

this should work:
ON value*value AND VAL("&H8"+"0"*7) GOTO @POS,@NEG

I need help writing an array rotate function [1,2,3,4,5] rotate left twice -> [3,4,5,1,2]

DEF ROTATE ARR[], N%, LEFT%
 IF LEFT% THEN
  FOR I=0 TO N%-1
   TMP=UNSHIFT(ARR)
   PUSH ARR, TMP
   NEXT
 ELSE
  FOR I=0 TO N%-1
   TMP=POP(ARR)
   SHIFT ARR, TMP
   NEXT
 ENDIF
 RETURN ARR
END
I can't remember what some of the basic array operation functions do like SHIFT

Is there a better function for inserting an array into an array?
DEF ARYINS A[],_P,IN[]
 IF !LEN(IN) THEN RETURN ENDIF
 DIM P=MIN(MAX(_P,0),LEN(A)-1)
 DIM A0[0]:COPY A0,A,0,P
 COPY A0,LEN(A0),IN
 DIM A1[0]:COPY A1,A,P,LEN(A)-P
 COPY A0,LEN(A0),A1:COPY A,A0
END
Edit: oh wait this thread is a meme. Where do I find the actual thread for critiquing functions lol Edit 2: can't find one, so I'm just going to pretend this is the thread I'm looking for. Edit 3: I've been 🅱️unked. This may not be the thread I'm looking for...

DEF ARYINS A[],_P,IN[]
  RETURN SUBST$("A[]",2,0,"IN[]")
END
should insert IN[] into A[]

DEF ARYINS A[],_P,IN[]
 IF !LEN(IN) THEN RETURN ENDIF
 DIM P=MIN(MAX(_P,0),LEN(A))
 DIM A0[0]:COPY A0,A,P,LEN(A)-P
 COPY A,P,IN:COPY A,P+LEN(IN),A0
END
Thanks for all the help lol