-
Notifications
You must be signed in to change notification settings - Fork 5
hasPrefix
Subhajit Sahu edited this page May 3, 2023
·
14 revisions
Examine if array starts with a prefix.
Similar: randomPrefix, prefixes, hasPrefix.
Similar: hasValue, hasPrefix, hasInfix, hasSuffix, hasSubsequence, hasPermutation, hasPath.
function hasPrefix(x, y, fc, fm)
// x: an array
// y: search prefix
// fc: compare function (a, b)
// fm: map function (v, i, x)
const xarray = require('extra-array');
var x = [1, 2, 3, 4];
xarray.hasPrefix(x, [1, 2]);
// → true
xarray.hasPrefix(x, [-1, -2]);
// → false
xarray.hasPrefix(x, [-1, -2], (a, b) => Math.abs(a) - Math.abs(b));
// → true
xarray.hasPrefix(x, [-1, -2], null, v => Math.abs(v));
// → true