Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

7 of 8
added 27 characters in body

JavaScript (Node.js), (削除) 79 (削除ここまで) 61 bytes

n=>'true int var for in if new try of do'.split` `.slice(0,n)

Try it online!

#How :

n => // the input (will be an integer) between 1 and 10 (both inclusive)
 ' // beginning our string 
 true int var for in if new try of do'. // space separated reserved words
 split` `. // turn it into an array every time there is a space we add to array
 slice(0,n) // return elements of array starting from 0 and upto n

If using operators is allowed (most likely will be since they are reserved words) then :

JavaScript (Node.js), (削除) 26 (削除ここまで) 25 bytes

n=>'|/^%+<&*-='.slice(-n)

Try it online!

Saved 8 bytes thanks to @Adam and 1 more byte thanks to @l4m2

How :

n => // input (integer from 0-9 inclusive)
 '|/^%+<&*-='. // operators make a shorter string 
 slice(-n) // outputs string chars from last upto n 
 // this works since all operators are single chars and not multi chars.

AltStyle によって変換されたページ (->オリジナル) /