Skip to content

hasPrefix

Subhajit Sahu edited this page Jun 28, 2020 · 14 revisions

Checks if array starts with a prefix. 🏃 📼 📦 🌔 📒

Similar: prefix, prefixes, hasPrefix.
Similar: hasValue, hasPrefix, hasInfix, hasSuffix, hasSubsequence, hasPermutation.

array.hasPrefix(x, y, [fc], [fm]);
// x:  an array
// y:  prefix?
// fc: compare function (a, b)
// fm: map function (v, i, x)
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

references

Clone this wiki locally