UNPKG

@azizbecha/strkit

Version:

strkit is a utility library offering a collection of essential string functions including validation, case conversion, truncation, and more. Ideal for both JavaScript and TypeScript developers to simplify string operations in their applications.

28 lines 930 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = isAnagram; /** * Checks if two strings are anagrams of each other. * Two strings are considered anagrams if they contain the same characters * in the same frequency, but arranged in any order. * * @param str1 - The first string. * @param str2 - The second string. * @returns True if the two strings are anagrams, false otherwise. * * @example * isAnagram("listen", "silent"); // Output: true * isAnagram("hello", "world"); // Output: false */ function isAnagram(str1, str2) { // Helper function to sort and normalize the string const normalize = (str) => str .replace(/[^a-zA-Z0-9]/g, '') .toLowerCase() .split('') .sort() .join(''); // Compare the normalized versions of the strings return normalize(str1) === normalize(str2); } //# sourceMappingURL=isAnagram.js.map