@extra-array/is-prefix
Version:
Checks if array starts with a prefix.
53 lines (42 loc) • 2.07 kB
Markdown
Checks if array starts with a prefix. [:running:] [:vhs:] [:package:] [:moon:] [:ledger:]
> Similar: [prefix], [prefixes], [isPrefix].<br>
> Similar: [isValue], [isPrefix], [isInfix], [isSuffix], [isSubsequence], [isPermutation].<br>
> This is part of package [extra-array].
[extra-array]: https://www.npmjs.com/package/extra-array
```javascript
array.isPrefix(x, y, [fc], [fm]);
// x: an array
// y: prefix?
// fc: compare function (a, b)
// fm: map function (v, i, x)
```
```javascript
const array = require('extra-array');
var x = [1, 2, 3, 4];
array.isPrefix(x, [1, 2]);
// true
array.isPrefix(x, [-1, -2]);
// false
array.isPrefix(x, [-1, -2], (a, b) => Math.abs(a) - Math.abs(b));
// true
array.isPrefix(x, [-1, -2], null, v => Math.abs(v));
// true
```
### references
- [Data.List.isPrefixOf: Haskell](https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:isPrefixOf)
- [List-Extra.isPrefixOf: elm](https://package.elm-lang.org/packages/elm-community/list-extra/7.1.0/List-Extra#isPrefixOf)
- [String.prototype.startsWith: MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
- [iterable-starts-with: @oprogramador](https://www.npmjs.com/package/iterable-starts-with)
[:running:]: https://npm.runkit.com/@extra-array/is-prefix
[:package:]: https://www.npmjs.com/package/@extra-array/is-prefix
[:moon:]: https://www.npmjs.com/package/@extra-array/is-prefix.min
[prefix]: https://github.com/nodef/extra-array/wiki/prefix
[prefixes]: https://github.com/nodef/extra-array/wiki/prefixes
[isPrefix]: https://github.com/nodef/extra-array/wiki/isPrefix
[:ledger:]: https://unpkg.com/@extra-array/is-prefix/
[:vhs:]: https://asciinema.org/a/332081
[isValue]: https://github.com/nodef/extra-array/wiki/isValue
[isInfix]: https://github.com/nodef/extra-array/wiki/isInfix
[isSuffix]: https://github.com/nodef/extra-array/wiki/isSuffix
[isSubsequence]: https://github.com/nodef/extra-array/wiki/isSubsequence
[isPermutation]: https://github.com/nodef/extra-array/wiki/isPermutation