Last active
April 5, 2022 16:35
-
-
Save nikonov91-dev/62f4d1fdb1ac0ef2b7f56c079169a3f8 to your computer and use it in GitHub Desktop.
This file contains 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
function deviceNamesSystem(dn) { | |
dn.push('kuojoa{-truncated-}'); | |
dn.push('fmgnwjjsfayewzpxslt1'); | |
dn.push('mixer'); | |
dn.push('mixer'); | |
const updatedDN = []; | |
let newName = ''; | |
let countMax = []; | |
const incrementCount = (c = '') => +c + 1; | |
const findMatch = ee => ee.match(/^(.+?)(\d*)$/); | |
dn.forEach( e => { | |
let foundMatch = findMatch(e); | |
if (!foundMatch[2] && !updatedDN.find( ee => findMatch(ee)[1] === foundMatch[1] )) { | |
newName = foundMatch[1]; | |
} else { | |
countMax = Math.max(...updatedDN | |
.filter(ee => findMatch(ee)[1] === foundMatch[1]) | |
.map( ee => findMatch(ee)[2])); | |
newName = foundMatch[1] + incrementCount(countMax) | |
} | |
updatedDN.push(newName); | |
}) | |
return updatedDN | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment