Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

anagram python

def isAnagram(A,B):
  if sorted(A) == sorted(B):
    print("Yes")
  else:
    print("No")
isAnagram("earth","heart") #Output: Yes

#Hope this helps:)
Comment

anagram

var firstWord = "Mary";
var secondWord = "Army";

isAnagram(firstWord, secondWord); // true

function isAnagram(first, second) {
  // For case insensitivity, change both words to lowercase.
  var a = first.toLowerCase();
  var b = second.toLowerCase();

  // Sort the strings, and join the resulting array to a string. Compare the results
  a = a.split("").sort().join("");
  b = b.split("").sort().join("");

  return a === b;
}
Comment

anagram

import java.util.Arrays;  
   
public class AnagramString {  
    static void isAnagram(String str1, String str2) {  
        String s1 = str1.replaceAll("s", "");  
        String s2 = str2.replaceAll("s", "");  
        boolean status = true;  
        if (s1.length() != s2.length()) {  
            status = false;  
        } else {  
            char[] ArrayS1 = s1.toLowerCase().toCharArray();  
            char[] ArrayS2 = s2.toLowerCase().toCharArray();  
            Arrays.sort(ArrayS1);  
            Arrays.sort(ArrayS2);  
            status = Arrays.equals(ArrayS1, ArrayS2);  
        }  
        if (status) {  
            System.out.println(s1 + " and " + s2 + " are anagrams");  
        } else {  
            System.out.println(s1 + " and " + s2 + " are not anagrams");  
        }  
    }  
   
    public static void main(String[] args) {  
        isAnagram("Keep", "Peek");  
        isAnagram("Mother In Law", "Hitler Woman");  
    }  
}
Comment

anagram

def anagram(a, b):
    return True if sorted(a) == sorted(b) else False

# Based on the answer below :D
Comment

anagram

// for 2 strings s1 and s2 to be anagrams
// both conditions should be True
// 1 their length is same or 
len(s1)==len(s2)
// 2 rearranging chars alphabetically make them equal or 
sorted(s1)==sorted(s2)
Comment

Anagram

const anagram = (str1, str2) => {
    return str1.toLowerCase().split('').sort().join('') === str2.toLowerCase().split('').sort().join('');
};

let test = anagram('Regallager', 'Lagerregal');
console.log(test);
Comment

anagram

//find the anagram if two word has the same characters for example word 1: listen, word 2: silent, if the characters are the same return true otherwise return false

//str1="eat"  str2="ate"
//str1="bar " str2="bare"
//str1="bba"  str2="aab"
function areAnagram(str1,str2)
{
    // Get lengths of both strings
    let n1 = str1.length;
    let n2 = str2.length;

    // If length of both strings is not same,
    // then they cannot be anagram
    if (n1 != n2)
        return false;

    // Sort both strings
    let x =str1.split("").sort();
    let y  =str2.split("").sort()
    console.log(x ,y);

    // Compare sorted strings
    for (let i = 0; i < n1; i++){

        if (x[i] != y[i])
            return false;
    }

    return true;
}
let str1="netsil";
let str2="listen";

console.log( areAnagram(str1,str2));
Comment

PREVIOUS NEXT
Code Example
Javascript :: findone mongoose 
Javascript :: javascript createelement innerhtml 
Javascript :: javascript change input value jquery 
Javascript :: node require fs not found 
Javascript :: run node.js code with python 
Javascript :: type checking js vscode 
Javascript :: deploy react to aws 
Javascript :: js string interpolation 
Javascript :: js read external json file js 
Javascript :: convert string to camelcase 
Javascript :: Navigator operation requested with a context that does not include a Navigator. 
Javascript :: how to install nuxtjs with tailwind css 
Javascript :: vitejs env 
Javascript :: json parse cause Unexpected token in JSON at position 550 
Javascript :: validate email or phone js 
Javascript :: get milliseconds since epoch for 12am today javascript 
Javascript :: incoroporate js and css file in html 
Javascript :: react native refresh flatlist on swipe down 
Javascript :: hello world program in javascript 
Javascript :: how to get class name of element in javascript 
Javascript :: react props have changed method 
Javascript :: MaterialStateProperty width 
Javascript :: js socket.emit 
Javascript :: how to use useref hook in react 
Javascript :: vue displaying a this.length 
Javascript :: email regex javascript 
Javascript :: jquery multiple ids same function 
Javascript :: make an object javascript 
Javascript :: vue js app component 
Javascript :: get filenem js 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =