UNPKG

locutus

Version:

Locutus other languages' standard libraries to JavaScript for fun and educational purposes

14 lines (13 loc) 488 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.find = find; function find(needle, haystack) { // discuss at: https://locutus.io/rust/find/ // parity verified: Rust 1.85 // original by: Kevin van Zonneveld (https://kvz.io) // example 1: find('or', 'Hello World') // returns 1: 7 // example 2: find('x', 'Hello World') // returns 2: -1 return String(haystack).indexOf(String(needle)); }