We’re rewarding the question askers & reputations are being recalculated! Read more.

Hot answers tagged

11

Moving from JavaScript to Japt As you may know, Japt is simply a shortened, extended version of JavaScript. I created Japt because I was tired of long property names, like String.fromCharCode(x) and Math.floor(x), and the tediousness of doing things such as creating a range. Here's the bare minimum you need to know when going from JavaScript to Japt: Japt ...


8

Compressing String Arrays UPDATE: The tools featured in this tip have since be rewritten, improved and integrated into my Japt interpreter. For the best results it is recommended that you use that compressor over any of those linked below. I'll revisit this tip when I have some more time and rewrite it with the new compressor in mind. Introduction If ...


6

Compressing strings Japt (currently) uses the shoco library for string compression. You can compress an arbitrary string using Oc, as long as it contains runs of lowercase letters: Oc"Hello, World!" This outputs HÁM, WŽld! (well, the Ž is technically an unprintable character). You can decompress this by wrapping it in backticks: `HÁM, WŽ...


6

Shortening Numbers With Char-Codes In Japt, you can use #, followed by a character to create a char-code. This comes in handy when shortening longer numbers. As @ETHproductions mentioned, this only works on three-digit runs in the range 100-255, unless you are willing to switch to UTF-8. Examples: 123 can be shortened to #{ 101 can be shortened to #e ...


5

Quick tip: Empty array [] Japt has a constant for an empty array: A. But, in order to access it, you must prepend a semicolon ; to your programme to use Japt's alternative constants, otherwise A will be 10. So using ;A actually offers a 0 byte saving over [], but will save you bytes if you need to assign your array to a variable (e.g., A=[]). However, if (...


4

Know the flags As per the latest meta consensus (Dec 2017), command-line flags are no longer counted towards bytes. It's really a great news for Japt since it has many flags for extra treatment on input/output. All available flags in Japt are described below, in the order of evaluation. The flags in the same group are exclusive to each other. Note that the ...


4

Evaluating JavaScript Japt allows you to execute raw JavaScript by wrapping it around $...$. For example, $alert("hello world")$ This can be shortened by taking advantage of Japt's auto-closing $ and ). $alert("hello world")$ can be shortened to $alert("hello world" Compressing JavaScript You can also compress JavaScript using Ox. If there is a ...


3

Take advantage of preset variables Variables A-S are preset to common values that take more than one byte to represent in Japt: A-G are 10-16. H is 32, I is 64, J is -1, L is 100. K is defined as new Date(), which you can manipulate in various ways. M and O are objects with various useful functions. You can learn more in the docs. P is the empty string, Q ...


3

Unicode shortcuts There are many common structures in Japt that just can't be stored in a single ASCII char, such as qS , p2 , mX{, } , etc. So to get around this, Japt has "Unicode shortcuts", which are characters in the range \xA1-\xDE (¡-Þ) which expand to these common structures. You can find a full list of these in the interpreter docs. Additionally, @...


3

Use auto-functions You most likely already know that @ and _ are shortcuts for XYZ{ and Z{Z, respectively (covered in the Unicode shortcuts answer). But sometimes you can make functions even shorter. Suppose you had an array of characters and you wanted to map each character to its char-code. You could do this with either of these: mX{Xc} m_c} But ...


3

Implicit Variable Assignment Whenever you start a new line in Japt the result of the previous line is automatically assigned to one of the input variables (U-Z), with the first line being U, the second V, and so on. Let's take an example: say you wanted to create 2 arrays to work with, one containing the numbers 1-10 and the other containing their squares. ...


3

Use multiple lines when necessary For most not-too-hard challenges, you can express the solution in just one line of Japt, as a sequence of applying built-in functions. But more complex ones will require to use looping constructs, recursion, or reusing large chunks of code. This is where multi-line programming comes in. Remove closing parens Task: Given ...


3

Know the Javascript Since any Japt code runs as transpiled JS, good understanding of JS operators and built-in methods helps a lot in golfing pieces of Japt code. Relevant JS tips Implicit casting, increment/decrement operators Some arithmetic/bitwise operator recipes This doesn't necessarily save bytes in Japt (due to shortcuts), but it's always good to ...


2

Generate the ASCII Range Update: Japt now has a constant for the ASCII range; the alternative value for E, accessible with ;. See this tip for more on Japt's constants. While Japt doesn't (yet) have a built-in for the ASCII range, you can generate an array of characters in just 5 bytes: 95odH Try it How It Works 95o creates the range [0,95) with each ...


2

When not to use í í is a useful built-in that pairs (or zips) two arrays or strings, and optionally maps each pair through a function. However, it currently has a few minor issues when given uneven arrays or strings: If the first array has more items than the second, the non-existent items in the second will be given as undefined. If the second array has ...


2

Fun with Auto-Functions As a follow-up to ETH's general tip on auto-functions, this tip will provide a few specific examples of byte saving tricks you can achieve with them, which I'll add to as I think of more. Get the largest integer in an array. Assume we have the array [3,1,4,2] assigned to variable U and we ant to retrieve the largest number from it. ...


1

Modify the Last Element in An Array Sometimes you may need to modify the last element in an array so here's an explanation of a short way of doing that. We'll be working with the array [2,4,8,32] assigned to input variable U and dividing the last integer (32) by 2. The obvious way to achieve this would be with this 9 byte solution (Demo): UhJUgJ /2 hnx ...


1

Remove unnecessary structural chars By structural chars, I mean {}, (), $, even " and `. You can typically remove these chars whenever they occur right at the end of a program (e.g. UmX{Xc +"; "} -> UmX{Xc +"; ). Additionally, you can remove parens or spaces whenever they appear in the following places: Up against a semicolon ; (or the end of the program);...


Only top voted, non community-wiki answers of a minimum length are eligible