|@schas002||Founder||I made this for you!|
Add function golf from HTML:
From JS, you can do this:
document.body.appendChild(document.createElement('script')).src = "http://schas002.github.com/js-function-golf/js-function-golf.js";
Theoretically, it is also possible to do this in function golf:
But importing function golf when function golf is already imported is overkill. :kappa:
Or you can just download http://schas002.github.com/js-function-golf/js-function-golf.js and just import
http://path.to/js-function-golf.js replacing the site
http://path.to/ with the directory where
Currently the golden rule is, only functions allowed are JS function golf functions, imported (using
i2s(123) instead of
123.toString(). The silver rule is, attributes are not allowed and replaced by existing function golf functions, so
sl("ABC") instead of
"ABC".length. Any other structures of JS are allowed.
Licensed under the ISC License. The full license follows.
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Important text ends here. Functions follow.
Don't forget - you are here forever.
Returns an element in the document called by the ID you gave to
Prints to the console whatever you gave to
p2a instead alerts the user with the data.
p2b is deprecated in favor of
Asks the user whatever you gave to
yn and returns the answer they gave, as a boolean. The answer is either "Yes" or "No".
yn2i instead returns an integer ("Yes" is 1, "No" is 0).
Asks the user whatever you gave to
i and returns the answer they gave. The answer is a string.
iai instead parses the answer as an integer that is returned.
Converts whatever you gave to
i2s to a string.
Converts a string you gave to
s2i to an integer.
Finds if is whatever you gave to
pr prime. Returns 1 if the number is prime, else 0.
Measures the length of the string you gave to
sloc() method returns the index of (the position of) the first occurrence of a specified text in a string.
siloc() method returns the index of the last occurrence of a specified text in a string.
ss() method searches a string for a specified value and returns the position of the match.
There are 3 methods for extracting a part of a string:
ssl() extracts a part of a string and returns the extracted part in a new string. The method takes 3 parameters: the initial string, the starting index (position), and the ending index (position).
subs() is similar to
ssl(). The difference is that
subs() cannot accept negative indexes.
subsbl() is similar to
ssl(). The difference is that the second parameter specifies the length of the extracted part.
sr(data, query, replacement)
sr() method replaces a specified value with another value in a string.
A string is converted to upper case with
A string is converted to lower case with
scc() joins two or more strings.
There are 2 safe methods for extracting string characters:
scha() method returns the character at a specified index (position) in a string.
schca() method returns the unicode of the character at a specified index in a string.
A string can be converted to an array with the
i2e() returns a string, with a number rounded and written using exponential notation.
i2fp() returns a string, with the number written with a specified number of decimals.
i2p() returns a string, with a number written with a specified length.
s2f() parses a string and returns a number. Spaces are allowed. Only the first number is returned.
mmax() can be used to find the lowest or highest value in a list of arguments.
mrn() returns a random number between 0 (inclusive), and 1 (exclusive).
mro() rounds a number to the nearest integer.
mrou() rounds a number up to the nearest integer.
mrod() rounds a number down to the nearest integer.
mrn() can be used together to return a random number between 0 and, say, 10. It can be golfed with
me // returns Euler's number mpi // returns PI m2r2 // returns the square root of 2 m2r_5 // returns the square root of 1/2 mln2 // returns the natural logarithm of 2 mln10 // returns the natural logarithm of 10 ml2e // returns base 2 logarithm of E ml10e // returns base 10 logarithm of E