Skip to main content
added 533 characters in body
Source Link
emanresu A
  • 44.4k
  • 5
  • 101
  • 240

Vyxal, 11 bytes

ṘKRṘ=vTvßhf

Try it Online!

ṘKRṘ        # Get suffixes
    =       # Find those that are equal
     vT     # Get truthy indices of each
       vßh  # For each, if it is truthy, get the first
          f # Flatten (remove empty values)

Or if we can return zeroes if the required value is not at the end:

Vyxal, 8 bytes

ṘKRṘ=ƛTh

Try it Online!

ṘKRṘ     # Over suffixes...
    =    # Check if each value is equal to the second input
     ƛ   # Map...
      Th # Find the first index where it is equal

Vyxal, 8 bytes

ṘKRṘ=ƛTh

Try it Online!

ṘKRṘ     # Over suffixes...
    =    # Check if each value is equal to the second input
     ƛ   # Map...
      Th # Find the first index where it is equal

Vyxal, 11 bytes

ṘKRṘ=vTvßhf

Try it Online!

ṘKRṘ        # Get suffixes
    =       # Find those that are equal
     vT     # Get truthy indices of each
       vßh  # For each, if it is truthy, get the first
          f # Flatten (remove empty values)

Or if we can return zeroes if the required value is not at the end:

Vyxal, 8 bytes

ṘKRṘ=ƛTh

Try it Online!

ṘKRṘ     # Over suffixes...
    =    # Check if each value is equal to the second input
     ƛ   # Map...
      Th # Find the first index where it is equal
Source Link
emanresu A
  • 44.4k
  • 5
  • 101
  • 240

Vyxal, 8 bytes

ṘKRṘ=ƛTh

Try it Online!

ṘKRṘ     # Over suffixes...
    =    # Check if each value is equal to the second input
     ƛ   # Map...
      Th # Find the first index where it is equal