JSFiddle - React, Tailwind, and code Playground

by yash009

JavaScript

var strs = ["eat","tea","tan","ate","nat","bat","rat","tar","pool","polo"]ana(strs);function ana(strs) {    // The result object    var ana = {};    for (var i in strs) {        let str = strs[i];        // creating a signature key using sorting function        var signature = sortString(str);        // If the signature already exists, we just push the word in the array        if (ana[signature] != null) {            ana[signature].push(str);        }         // Otherwise create a key        else {            ana[signature] = [ str ];        }    }    console.log(Object.values(ana));}
function sortString(word) {    let temp = word.split('').sort().join('');    return temp;}