Array.indexOf/lastIndexOf implementation