<commit_before>/* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */
/* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */
import escapeRegExp from 'lodash.escaperegexp';

/**
 * SLDS recommends auto-complete/search inputs menus have a limit of 10 items.
 */
const filter = ({ inputValue, limit = 10, options, selection }) =>
	options
		.filter((option) => {
			const searchTermFound = option.label
				? option.label.match(new RegExp(escapeRegExp(inputValue), 'ig'))
				: false;
			const isSeparator = option.type === 'separator';
			const notAlreadySelected = !selection.includes(option);

			return (
				(!inputValue || isSeparator || searchTermFound) && notAlreadySelected
			);
		})
		.splice(0, limit);

export default filter;<commit_msg>Fixed filter function to remove already selected options from dropdown<commit_after>/* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */
/* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */
import escapeRegExp from 'lodash.escaperegexp';

/**
 * SLDS recommends auto-complete/search inputs menus have a limit of 10 items.
 */
const filter = ({ inputValue, limit = 10, options, selection }) =>
	options
		.filter((option) => {
			const searchTermFound = option.label
				? option.label.match(new RegExp(escapeRegExp(inputValue), 'ig'))
				: false;
			const isSeparator = option.type === 'separator';
			const notAlreadySelected = !selection.some((sel) => sel.id === option.id);

			return (
				(!inputValue || isSeparator || searchTermFound) && notAlreadySelected
			);
		})
		.splice(0, limit);

export default filter;
{'fraction_non_alphanumeric': 0.13256658595641646, 'fraction_numerical': 0.012106537530266344, 'mean_word_length': 4.070552147239264, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '749767', 'n_tokens_mistral': 554, 'n_tokens_neox': 475, 'n_words': 140}