Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const startsWith = (stringValue, searchValue, position) => {
- if (typeof stringValue === "string" && (["string", "boolean", "number"].includes(typeof searchValue) || searchValue instanceof Array)) {
- if (position) return stringValue.slice(position).slice(0, searchValue.toString().length) === searchValue.toString()
- else return stringValue.slice(0, searchValue.toString().length) === searchValue.toString()
- } else return false
- }
- // example
- // code | expected output
- startsWith("testing oof", "testing") // true
- startsWith("testing oof", "oof", 8) // true
- //
- startsWith() // false
- startsWith("testing oof") // false
- startsWith("testing oof", "oof") // false
- startsWith("testing oof", "oof", 10) // false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement