Comments

protocola month ago

not to fancy algo `const solve = (strArray) => { const arr = [] for(let char of strArray){ let letters = char.split("").sort().join("") arr.push(letters.toLowerCase()) }

return arr.every(el => el === arr[0]) }; `

Ameliorated Tugrik3 months ago

Well, I have no idea why the code is unable to pass the system validation.... I've checked it in a browser console - works perfectly! It might not like me not using curly brackets.

const solve = (arr) => {
  const hashTable = new Set();
  arr.forEach(i => hashTable.add(i.toLowerCase().split('').sort().join('')));
  return hashTable.size === 1
};

Michal Mucha4 months ago

const solve = (strArray) => { const result = []; strArray.forEach((word) => { const sortedWord = word.toLowerCase().split("").sort().join(""); if (!result.includes(sortedWord)) { result.push(sortedWord); } }); return result.length === 1; };

Forges4 months ago

const solve = strArray => {
  const newArr = strArray.map((item, index) => item.split('').sort().join('').toLowerCase());

  return newArr.every(item => item === newArr[0]);
};

Reuven Naor5 months ago

const solve = (strArray) => strArray.every(val => val.toUpperCase().split('').sort().toString() === strArray[0].toUpperCase().split('').sort().toString() );

Rhode Island Mexican Peso Mexican Unidad de Inversion (UDI) Handcrafted Metal Cheesea year ago

const solve = (strArray) => {
  return strArray
    .map(word => word.toLowerCase().split("").sort().join(""))
    .every((word, i, arr) => word === arr[0]);
};

Intranet Cambridgeshirea year ago

// Now with reducers! const solve = (strArray) => { const returnVal = strArray.reduce((prevVal, currVal, i, arr) => { // exec a reducer to find a non-match if (!charMatch(prevVal, currVal)) { arr.splice(1) return false } return currVal }) return returnVal === false ? false : true }

// replaces a string char at any found position const charRemover = (stringB, charA) => stringB.toLowerCase().replace(charA.toLowerCase(), '');

const charMatch = (stringA, stringB) => { // this checks strA's length after a split reduce applied to strB. if there // is a remaining char, the anagram fails (swap AB str in the || condition) return !(stringA.split('').reduce((cval, val) => charRemover(cval, val), stringB).length || stringB.split('').reduce((cval, val) => charRemover(cval, val), stringA).length); };

SASa year ago

const solve = (strArray) => { let result = []; strArray.forEach(word => { // splitting the string into individual letter array let arr = word.split(''); // sorting that array in alphabetical order let sorted = arr.sort(); // create a new string of all the newly sorted strings let newStr = sorted.join('') // making all letters lowercase so deep equal works let lowerCased = newStr.toLowerCase() // pushing the string into an array result.push(lowerCased); }) // setting a variable up to check the newly created array of alphabetized, lowercase string elements let first = result[0]; // returning true if all the elments are deeply equal and false if not return result.every(function(element) { return element === first; }) };