Answers for "anagram solution in js"

5

javascript anagram check

const areAnagram = (str1, str2) => 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
Posted by: Guest on July-03-2020
0

check anagramm in typescript

'use strict';

let text1: string = 'mode';
let text2: string = 'demo';

function anagram(text1: string, text2: string): boolean {
  if (text1.length !== text2.length) {
    return false;
  }
  if (text1 === text2) {
    return false;
  }
  let charString1 = text1.split('').sort().join('');
  let charString2 = text2.split('').sort().join('');

  return charString1 === charString2;
}

console.log(anagram(text1, text2));
Posted by: Guest on December-09-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language