Last active
May 7, 2020 00:55
-
-
Save hillal20/be6d335d84512167fa35d076456cc043 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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