R, (削除) 31 (削除ここまで) 29 bytes
function(a,b)pmax(a,b)+a*!a-b
pmax takes the parallel maximum of the two (or more) arrays (recycling the shorter as needed).
I was looking at Luis Mendo's comment and obviously I realized the approach could work for R as well. That got me to 30 bytes, but then I started playing around with different ways of getting indices instead to improve my original answer, and stumbled upon !a-b as TRUE where a==b and FALSE otherwise, equivalent to a==b. However, for whatever reason, R doesn't require parentheses around !a-b as it does for a==b, which saved me two bytes.
As mentioned by JDL in the comments , this works because ! (negation) has lower precedence than the binary operator - in R, which is strange.
R, (削除) 31 (削除ここまで) 29 bytes
function(a,b)pmax(a,b)+a*!a-b
pmax takes the parallel maximum of the two (or more) arrays (recycling the shorter as needed).
I was looking at Luis Mendo's comment and obviously I realized the approach could work for R as well. That got me to 30 bytes, but then I started playing around with different ways of getting indices instead to improve my original answer, and stumbled upon !a-b as TRUE where a==b and FALSE otherwise, equivalent to a==b. However, for whatever reason, R doesn't require parentheses around !a-b as it does for a==b, which saved me two bytes.
R, (削除) 31 (削除ここまで) 29 bytes
function(a,b)pmax(a,b)+a*!a-b
pmax takes the parallel maximum of the two (or more) arrays (recycling the shorter as needed).
I was looking at Luis Mendo's comment and obviously I realized the approach could work for R as well. That got me to 30 bytes, but then I started playing around with different ways of getting indices instead to improve my original answer, and stumbled upon !a-b as TRUE where a==b and FALSE otherwise, equivalent to a==b. However, for whatever reason, R doesn't require parentheses around !a-b as it does for a==b, which saved me two bytes.
As mentioned by JDL in the comments , this works because ! (negation) has lower precedence than the binary operator - in R, which is strange.
R, 31(削除) 31 (削除ここまで) 29 bytes
function(a,b)pmax(a,b)+a*(a==b)!a-b
pmax takes the parallel maximum of the two (or more) arrays (recycling the shorter as needed).
I was looking at Luis Mendo's comment and obviously I realized the approach could work for R as well. That got me to 30 bytes, but then I started playing around with different ways of getting indices instead to improve my original answer, and stumbled upon a==b!a-b returns a list ofas TRUE where a==b and FALSE indices where the lists are equalotherwise, and they are coercedequivalent to 1a==b and. However, for whatever reason, R doesn't require parentheses around 0!a-b respectivelyas it does for a==b, which saved me two bytes.
R, 31 bytes
function(a,b)pmax(a,b)+a*(a==b)
pmax takes the parallel maximum of the two (or more) arrays (recycling the shorter as needed). a==b returns a list of TRUE and FALSE indices where the lists are equal, and they are coerced to 1 and 0 respectively.
R, (削除) 31 (削除ここまで) 29 bytes
function(a,b)pmax(a,b)+a*!a-b
pmax takes the parallel maximum of the two (or more) arrays (recycling the shorter as needed).
I was looking at Luis Mendo's comment and obviously I realized the approach could work for R as well. That got me to 30 bytes, but then I started playing around with different ways of getting indices instead to improve my original answer, and stumbled upon !a-b as TRUE where a==b and FALSE otherwise, equivalent to a==b. However, for whatever reason, R doesn't require parentheses around !a-b as it does for a==b, which saved me two bytes.
R, 31 bytes
function(a,b)pmax(a,b)+a*(a==b)
pmax takes the parallel maximum of the two (or more) arrays (recycling the shorter as needed). a==b returns a list of TRUE and FALSE indices where the lists are equal, and they are coerced to 1 and 0 respectively.