You are viewing a single comment's thread. Return to all comments →
javascript's array can add more elements dynamically by specifying any index
function makeAnagram(a, b) { let vector = [] for(let element of a) { let index = element.charCodeAt(0) - 97 vector[index] = vector[index] || 0 vector[index] += 1; } for(let element of b){ let index = element.charCodeAt(0) - 97 vector[index] = vector[index] || 0 vector[index] -=1 } return vector.reduce((a,b) => Math.abs(a) + Math.abs(b)) }
Seems like cookies are disabled on this browser, please enable them to open this website
Strings: Making Anagrams
You are viewing a single comment's thread. Return to all comments →
javascript's array can add more elements dynamically by specifying any index