Skip to content

Latest commit

 

History

History
30 lines (24 loc) · 686 Bytes

check-if-two-strings-are-anagram.mdx

File metadata and controls

30 lines (24 loc) · 686 Bytes
category contributors created title updated
String
mahdiyar
2020-05-07
Check if two strings are anagram
2021-10-13

JavaScript version

const areAnagram = (str1, str2) =>
    str1.toLowerCase().split('').sort().join('') === str2.toLowerCase().split('').sort().join('');

TypeScript version

const areAnagram = (str1: string, str2: string): boolean =>
    str1.toLowerCase().split('').sort().join('') === str2.toLowerCase().split('').sort().join('');

Examples

areAnagram('listen', 'silent'); // true
areAnagram('they see', 'the eyes'); // true
areAnagram('node', 'deno'); // true