1

I want to convert following code (ignore console.log) to jsfuck convention where only characters []()!+ are allowed (but here for clarity also numbers and strings with a-Z and 0-9 chars are allowed (wrapped by double quotes) - because conversion such strings/numbers to []()!+ is easy)

console.log(
    [1,2,3,4,5].map(x=>x**2)
)

After partial conversion I have

console.log(
    [1,2,3,4,5]["map"]([]["fill"]["constructor"]("return(2)"))
)

The problem is that I'm unable to pass argument x into map function.

Question: How to convert function x=>x**2 to jsf and pass it as map argument?

(I don't want to use 'eval' like solutions where we put map inside string which will be executed as code e.g. []["fill"]["constructor"]('return [1,2,3,4,5].map(x=>x**2)')() - this is forbidden)

j08691
  • 204,283
  • 31
  • 260
  • 272
Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345

2 Answers2

1

The function constructor takes more than one argument:

 []["fill"]["constructor"]('x', 'return x ** 2;')
Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151
0

Alternative solution - it also allows to define multi-arg methods

console.log(
  [1,2,3,4,5].map( 
    []["fill"]["constructor"]('return x=>x**2')()
  )
)
Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345