r/programminghorror • • Mar 20 '26
Javascript Javascript no keyword style
let functionsFormatnumber = (
parametersNumber,
functionRawString = Math.floor(parametersNumber).toString()
) => (
functionRawString.match(new RegExp(`(^.{${(functionRawString.length - 1) % 3 + 1}})|(.{3})`, "g")).join(",")
);This is a function that formats number into a string with a comma seperating every 3 digits.
To avoid using keywords, it uses an anonymous function.
65
Upvotes
8
u/seniorsassycat Mar 20 '26
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat
7
u/chamberlain2007 Mar 21 '26
They should make a script language that has types
2
u/mediocrobot Mar 21 '26
The function and parameter names confused me. Why prefix things with
functionandparameter? Without reading your explanation, my initial assumption was thatfunctionRawStringwas supposed to accept a stringified function andparametersNumberwas supposed to be the number of parameters the stringified function accepted.1
u/SerpentJoe Mar 21 '26
toLocaleStringis not a keyword59
u/[deleted] Mar 20 '26
[removed] — view removed comment
1
u/[deleted] Mar 25 '26
[removed] — view removed comment