“Contoh Anagram JavaScript” Kode Jawaban

Program Anagram di JavaScript

function checkStringsAnagram(a, b) {
   let len1 = a.length;
   let len2 = b.length;
   if(len1 !== len2){
      console.log('Invalid Input');
      return
   }
   let str1 = a.split('').sort().join('');
   let str2 = b.split('').sort().join('');
   if(str1 === str2){
      console.log("True");
   } else { 
      console.log("False");
   }
}
checkStringsAnagram("indian","ndiani")
night demon

Contoh Anagram JavaScript

function anagram(name, words) {
	var a = name.replace(/\s/g,'').toLowerCase().split('').sort().join('');
	var b = words.join('').split('').sort().join('');
	return a == b;
}
Restu Wahyu Saputra

Anagram JS

function isAnagram(stringA, stringB) {
  // Sanitizing
  stringA = stringA.toLowerCase().replace(/[\W_]+/g, "");
  stringB = stringB.toLowerCase().replace(/[\W_]+/g, "");

  // sorting
  const stringASorted = stringA.split("").sort().join("");
  const stringBSorted = stringB.split("").sort().join("");

  return stringASorted === stringBSorted;
}
Fylls

Program Anagram di JavaScript

    function group_anagrams(arr) {
      let   sortedArr = arr.map(item => item.split('').sort().join(''));
      let setArr = new Set(sortedArr);
      let reducedObj = {};
      for (let setItem of setArr) {
        let indexArr = sortedArr.reduce((acc, cur, index) => {
          if (setItem === cur) {
            acc.push(index);
          }
          return acc;
        }, []);
        reducedObj[setItem] = indexArr;
      }
      let finalArr = [];
      for (let reduceItem in reducedObj) {
        finalArr.push(reducedObj[reduceItem].map(item => arr[item]));
      }
      return finalArr;
    }
    group_anagrams(['car','cra','rca', 'cheese','ab','ba']);
Clear Cardinal

Contoh Anagram JavaScript

function anagram(name, words) {
	name =  name.toLowerCase().split('').sort().join('').trim();
  words = words.join('').toLowerCase().split('').sort().join('');
  return name === words;
}
Restu Wahyu Saputra

Jawaban yang mirip dengan “Contoh Anagram JavaScript”

Pertanyaan yang mirip dengan “Contoh Anagram JavaScript”

Lebih banyak jawaban terkait untuk “Contoh Anagram JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya