UNPKG

@extra-array/has-permutation

Version:

Checks if array has a permutation.

63 lines (47 loc) 2.2 kB
Checks if array has a permutation. [:package:](https://www.npmjs.com/package/@extra-array/has-permutation) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/has-permutation) [:vhs:](https://asciinema.org/a/343740) [:moon:](https://www.npmjs.com/package/@extra-array/has-permutation.min) [:scroll:](https://unpkg.com/@extra-array/has-permutation/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > Similar: [permutation], [permutations], [hasPermutation].<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.hasPermutation(x, y, [fc], [fm]); // x: an array // y: permutation? // fc: map function (v, i, x) // fm: compare function (a, b) ``` ```javascript const array = require("extra-array"); var x = [1, 2, 3, 4]; array.hasPermutation(x, [4, 3, 2, 1]); // true array.hasPermutation(x, [3, -1, -2, 4]); // false array.hasPermutation(x, [3, -1, -2, 4], (a, b) => Math.abs(a) - Math.abs(b)); // true array.hasPermutation(x, [3, -1, -2, 4], null, v => Math.abs(v)); // true ``` <br> <br> ## References - [Data.List.permutations: Haskell](https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:permutations) - [List-Extra.isPermutationOf: elm](https://package.elm-lang.org/packages/elm-community/list-extra/7.1.0/List-Extra#isPermutationOf) [permutation]: https://github.com/nodef/extra-array/wiki/permutation [permutations]: https://github.com/nodef/extra-array/wiki/permutations [hasPermutation]: https://github.com/nodef/extra-array/wiki/hasPermutation [hasValue]: https://github.com/nodef/extra-array/wiki/hasValue [hasPrefix]: https://github.com/nodef/extra-array/wiki/hasPrefix [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 [hasPath]: https://github.com/nodef/extra-array/wiki/hasPath