A variable named keywords
is declared and assigned an array of 10 string values, including common programming concepts such as variable types and function calls.
var keywords = ['type', 'id', 'params',
'body', 'generator', 'async',
'range', 'expression', 'callee',
'arguments'];
/**
* Defines a list of key words used in function declarations.
* @constant {string[]} keywords
*/
const keywords = [
// Common function declaration attributes
'type', 'id', 'params',
// Function behavior and syntax
'body', 'generator', 'async',
// Function parameter or argument properties
'range', 'expression', 'callee',
// Function argument properties
'arguments'
];
/**
* Filters a list of keywords based on a specified pattern.
* @param {string[]} keywords - The list of keywords to filter.
* @param {string} pattern - The pattern to match.
* @returns {string[]} The filtered list of keywords.
*/
function filterKeywords(keywords, pattern) {
return keywords.filter(keyword => keyword.includes(pattern));
}
// Example usage:
const filteredKeywords = filterKeywords(keywords, 'async');
console.log(filteredKeywords); // Output: ['async', 'async', 'generator']
keywords
is declared and assigned an array of strings.keywords
array contains the following strings:
type
id
params
body
generator
async
range
expression
callee
arguments