I want to sort string inside an array, not a normal sorting because if I do so the result will be:
var a = ["dcb","acb","gfe"];
console.log(a.sort());
the answer would be:
["acb","dcb","gfe"]
which I don't want, the sorted array I want is sorting of string inside the array, For eg:
var a = ["dcb","acb","gfe"];
expected answer :
["bcd","abc","efg"]
hope my question is clear to you :)
a.map(s => s.split('').sort().join(''))a.map(s=>[...s].sort().join('')).map()method iteratates through each element of the array, and code within map callback sorts that individual element. This will work.