UNPKG

@extra-array/has-prefix

Version:

Checks if array starts with a prefix.

65 lines (49 loc) 2.32 kB
Checks if array starts with a prefix. [:package:](https://www.npmjs.com/package/@extra-array/has-prefix) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/has-prefix) [:vhs:](https://asciinema.org/a/343741) [:moon:](https://www.npmjs.com/package/@extra-array/has-prefix.min) [:scroll:](https://unpkg.com/@extra-array/has-prefix/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > Similar: [prefix], [prefixes], [hasPrefix].<br> > Similar: [hasValue], [hasPrefix], [hasInfix], [hasSuffix], [hasSubsequence], [hasPermutation], [hasPath]. > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array <br> ```javascript array.hasPrefix(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.hasPrefix(x, [1, 2]); // true array.hasPrefix(x, [-1, -2]); // false array.hasPrefix(x, [-1, -2], (a, b) => Math.abs(a) - Math.abs(b)); // true array.hasPrefix(x, [-1, -2], null, v => Math.abs(v)); // true ``` <br> <br> ## 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) [prefix]: https://github.com/nodef/extra-array/wiki/prefix [prefixes]: https://github.com/nodef/extra-array/wiki/prefixes [hasPrefix]: https://github.com/nodef/extra-array/wiki/hasPrefix [hasValue]: https://github.com/nodef/extra-array/wiki/hasValue [hasInfix]: https://github.com/nodef/extra-array/wiki/hasInfix [hasSuffix]: https://github.com/nodef/extra-array/wiki/hasSuffix [hasSubsequence]: https://github.com/nodef/extra-array/wiki/hasSubsequence [hasPermutation]: https://github.com/nodef/extra-array/wiki/hasPermutation [hasPath]: https://github.com/nodef/extra-array/wiki/hasPath