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 Answer

Commonmark migration
Source Link

#JavaScript (ES6), (削除) 53 (削除ここまで)(削除) 49 (削除ここまで)(削除) 45 (削除ここまで) 43 bytes

JavaScript (ES6), (削除) 53 (削除ここまで)(削除) 49 (削除ここまで)(削除) 45 (削除ここまで) 43 bytes

a=>b=>a.map((x,y)=>(y=b[y])>x?y:y<x?x:x+y)
  • 4 bytes saved by borrowing a trick from Mr. Xcoder.
  • 2 bytes saved thanks to Arnauld.

##Try it

Try it

o.innerText=(f=
a=>b=>a.map((x,y)=>(y=b[y])>x?y:y<x?x:x+y)
)(i.value=[1,3,3.2,2.3])(j.value=[3,1,3.2,2.6]);oninput=_=>o.innerText=f(i.value.split`,`.map(eval))(j.value.split`,`.map(eval))
<input id=i><input id=j><pre id=o>


##Explanation

Explanation

a=>b=>

Anonymous function taking the 2 arrays as arguments via parameters a and b, in currying syntax (i.e., call with f(a)(b)

a.map((x,y)=> )

Map over the first array, passing each element through a function where x is the current element and y is the current index.

(y=b[y])

Get the element at index y in the second array and assign that as the new value of y.

>x?y

Check if y is greater than x and, if so, return y.

:y<x?x

Else, check if y is less than x and, if so, return x

:x+y

Else, return the sum of x and y. (Multiplying x or y by 2 would also work here, for the same number of bytes.)

#JavaScript (ES6), (削除) 53 (削除ここまで)(削除) 49 (削除ここまで)(削除) 45 (削除ここまで) 43 bytes

a=>b=>a.map((x,y)=>(y=b[y])>x?y:y<x?x:x+y)
  • 4 bytes saved by borrowing a trick from Mr. Xcoder.
  • 2 bytes saved thanks to Arnauld.

##Try it

o.innerText=(f=
a=>b=>a.map((x,y)=>(y=b[y])>x?y:y<x?x:x+y)
)(i.value=[1,3,3.2,2.3])(j.value=[3,1,3.2,2.6]);oninput=_=>o.innerText=f(i.value.split`,`.map(eval))(j.value.split`,`.map(eval))
<input id=i><input id=j><pre id=o>


##Explanation

a=>b=>

Anonymous function taking the 2 arrays as arguments via parameters a and b, in currying syntax (i.e., call with f(a)(b)

a.map((x,y)=> )

Map over the first array, passing each element through a function where x is the current element and y is the current index.

(y=b[y])

Get the element at index y in the second array and assign that as the new value of y.

>x?y

Check if y is greater than x and, if so, return y.

:y<x?x

Else, check if y is less than x and, if so, return x

:x+y

Else, return the sum of x and y. (Multiplying x or y by 2 would also work here, for the same number of bytes.)

JavaScript (ES6), (削除) 53 (削除ここまで)(削除) 49 (削除ここまで)(削除) 45 (削除ここまで) 43 bytes

a=>b=>a.map((x,y)=>(y=b[y])>x?y:y<x?x:x+y)
  • 4 bytes saved by borrowing a trick from Mr. Xcoder.
  • 2 bytes saved thanks to Arnauld.

Try it

o.innerText=(f=
a=>b=>a.map((x,y)=>(y=b[y])>x?y:y<x?x:x+y)
)(i.value=[1,3,3.2,2.3])(j.value=[3,1,3.2,2.6]);oninput=_=>o.innerText=f(i.value.split`,`.map(eval))(j.value.split`,`.map(eval))
<input id=i><input id=j><pre id=o>


Explanation

a=>b=>

Anonymous function taking the 2 arrays as arguments via parameters a and b, in currying syntax (i.e., call with f(a)(b)

a.map((x,y)=> )

Map over the first array, passing each element through a function where x is the current element and y is the current index.

(y=b[y])

Get the element at index y in the second array and assign that as the new value of y.

>x?y

Check if y is greater than x and, if so, return y.

:y<x?x

Else, check if y is less than x and, if so, return x

:x+y

Else, return the sum of x and y. (Multiplying x or y by 2 would also work here, for the same number of bytes.)

added 732 characters in body
Source Link
Shaggy
  • 45k
  • 4
  • 39
  • 95

#JavaScript (ES6), (削除) 53 (削除ここまで) (削除) 49 (削除ここまで) (削除) 45 (削除ここまで) 43 bytes

a=>b=>a.map((x,y)=>(y=b[y])>x?y:y<x?x:x*2x+y)
  • 4 bytes saved by borrowing a trick from Mr. Xcoder.
  • 2 bytes saved thanks to Arnauld.

##Try it

o.innerText=(f=
a=>b=>a.map((x,y)=>(y=b[y])>x?y:y<x?x:x*2x+y)
)(i.value=[1,3,3.2,2.3])(j.value=[3,1,3.2,2.6]);oninput=_=>o.innerText=f(i.value.split`,`.map(eval))(j.value.split`,`.map(eval))
<input id=i><input id=j><pre id=o>


##Explanation

a=>b=>

Anonymous function taking the 2 arrays as arguments via parameters a and b, in currying syntax (i.e., call with f(a)(b)

a.map((x,y)=> )

Map over the first array, passing each element through a function where x is the current element and y is the current index.

(y=b[y])

Get the element at index y in the second array and assign that as the new value of y.

>x?y

Check if y is greater than x and, if so, return y.

:y<x?x

Else, check if y is less than x and, if so, return x

:x+y

Else, return the sum of x and y. (Multiplying x or y by 2 would also work here, for the same number of bytes.)

#JavaScript (ES6), (削除) 53 (削除ここまで) (削除) 49 (削除ここまで) (削除) 45 (削除ここまで) 43 bytes

a=>b=>a.map((x,y)=>(y=b[y])>x?y:y<x?x:x*2)
  • 4 bytes saved by borrowing a trick from Mr. Xcoder.
  • 2 bytes saved thanks to Arnauld.

##Try it

o.innerText=(f=
a=>b=>a.map((x,y)=>(y=b[y])>x?y:y<x?x:x*2)
)(i.value=[1,3,3.2,2.3])(j.value=[3,1,3.2,2.6]);oninput=_=>o.innerText=f(i.value.split`,`.map(eval))(j.value.split`,`.map(eval))
<input id=i><input id=j><pre id=o>

#JavaScript (ES6), (削除) 53 (削除ここまで) (削除) 49 (削除ここまで) (削除) 45 (削除ここまで) 43 bytes

a=>b=>a.map((x,y)=>(y=b[y])>x?y:y<x?x:x+y)
  • 4 bytes saved by borrowing a trick from Mr. Xcoder.
  • 2 bytes saved thanks to Arnauld.

##Try it

o.innerText=(f=
a=>b=>a.map((x,y)=>(y=b[y])>x?y:y<x?x:x+y)
)(i.value=[1,3,3.2,2.3])(j.value=[3,1,3.2,2.6]);oninput=_=>o.innerText=f(i.value.split`,`.map(eval))(j.value.split`,`.map(eval))
<input id=i><input id=j><pre id=o>


##Explanation

a=>b=>

Anonymous function taking the 2 arrays as arguments via parameters a and b, in currying syntax (i.e., call with f(a)(b)

a.map((x,y)=> )

Map over the first array, passing each element through a function where x is the current element and y is the current index.

(y=b[y])

Get the element at index y in the second array and assign that as the new value of y.

>x?y

Check if y is greater than x and, if so, return y.

:y<x?x

Else, check if y is less than x and, if so, return x

:x+y

Else, return the sum of x and y. (Multiplying x or y by 2 would also work here, for the same number of bytes.)

added 63 characters in body
Source Link
Shaggy
  • 45k
  • 4
  • 39
  • 95

#JavaScript (ES6), (削除) 53 (削除ここまで) (削除) 49 (削除ここまで) (削除) 45 (削除ここまで) 43 bytes

a=>b=>a.map((x,y)=>(y=b[y])>x?y:y<x?x:x*2)
  • 4 bytes saved by borrowing a trick from Mr. Xcoder.
  • 2 bytes saved thanks to Arnauld.

##Try it

o.innerText=(f=
a=>b=>a.map((x,y)=>(y=b[y])>x?y:y<x?x:x*2)
)(i.value=[1,3,3.2,2.3])(j.value=[3,1,3.2,2.6]);oninput=_=>o.innerText=f(i.value.split`,`.map(eval))(j.value.split`,`.map(eval))
<input id=i><input id=j><pre id=o>

#JavaScript (ES6), (削除) 53 (削除ここまで) (削除) 49 (削除ここまで) (削除) 45 (削除ここまで) 43 bytes

a=>b=>a.map((x,y)=>(y=b[y])>x?y:y<x?x:x*2)
  • 4 bytes saved by borrowing a trick from Mr. Xcoder.
  • 2 bytes saved thanks to Arnauld.

#JavaScript (ES6), (削除) 53 (削除ここまで) (削除) 49 (削除ここまで) (削除) 45 (削除ここまで) 43 bytes

a=>b=>a.map((x,y)=>(y=b[y])>x?y:y<x?x:x*2)
  • 4 bytes saved by borrowing a trick from Mr. Xcoder.
  • 2 bytes saved thanks to Arnauld.

##Try it

o.innerText=(f=
a=>b=>a.map((x,y)=>(y=b[y])>x?y:y<x?x:x*2)
)(i.value=[1,3,3.2,2.3])(j.value=[3,1,3.2,2.6]);oninput=_=>o.innerText=f(i.value.split`,`.map(eval))(j.value.split`,`.map(eval))
<input id=i><input id=j><pre id=o>

added 63 characters in body
Source Link
Shaggy
  • 45k
  • 4
  • 39
  • 95
Loading
Source Link
Shaggy
  • 45k
  • 4
  • 39
  • 95
Loading

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