Skip to content

Instantly share code, notes, and snippets.

@hillal20
Last active May 7, 2020 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hillal20/be6d335d84512167fa35d076456cc043 to your computer and use it in GitHub Desktop.
Save hillal20/be6d335d84512167fa35d076456cc043 to your computer and use it in GitHub Desktop.
const arr = ["art","tra","filo","olif",'bilal', "labil", "hi", "ho"];
let el = [];
const newArr = [];
const obj ={}
let te
let result = [];
const fn = (arr)=>{
for(let i = 0 ; i < arr.length ; i++){
el = arr[i].split("").sort().join("");
obj[arr[i]] = el
}
let objValues1 = Object.values(obj);
const tempObj = {}
objValues1.forEach(el =>{
tempObj[el] = true;
})
const objKeys = Object.keys(obj);
let objValues2 = Object.keys(tempObj);
for (let i = 0; i < objValues2.length ; i ++){
let currentValue = objValues2[i]
let count = 0;
objValues1.forEach(e=>{
if ( e === currentValue) {
count ++;
}
});
for(let key in obj ){
if(obj[key] === currentValue && count > 1 ){
result.push(`${ key }---${currentValue}`);
}
}
}
return result
}
fn(arr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment