# CodeChallenge
```javascript=
const removeDuplicates = (arr, attrib) => {
const hash = {}
const newArray = arr.filter( v => {
if (!hash[v[attrib]]) {
hash[v[attrib]] = true;
return true;
}
})
return newArray;
}
const arr = [
{'clave clave':1, valor:'uno'},
{'clave clave':2, valor:'dos'},
{'clave clave':3, valor:'tres'},
{'clave clave':1, valor:'unoUno'},
{'clave clave':4, valor:'Cuatro'},
{'clave clave':2, valor:'dosdos'}
]
removeDuplicates(arr, 'clave clave');
//pila balanceada
// const expression = '{([])}';
const expression = '[()]{}{[()()]()}';
console.log('is balanced: ', isBalanced(expression));
function isBalanced(expression){
const opening = new Set();
opening.add('[');
opening.add('{');
opening.add('(');
const closing = new Set();
closing.add(']');
closing.add('}');
closing.add(')');
const map = new Map();
map.set(']', '[');
map.set(')', '(');
map.set('}', '{');
const stack = [];
if (expression.length%2 !== 0 ){
return false;
}
for (const char of expression) {
if (opening.has(char)){
stack.push(char);
} else {
if ( stack.length === 0 ){
return false;
} else {
if (stack[stack.length-1] === map.get(char)){
stack.pop();
} else {
return false;
}
}
}
}
return (stack.length)? false : true;
}
//find second highest number in array
const myFn = (intArray, highest=2) => {
const sol = {
num : null,
count : 0
};
for (let indexI = 0; indexI < intArray.length; indexI++) {
for (let indexJ = indexI+1 ; indexJ < intArray.length; indexJ++) {
const element = intArray[indexJ];
if (element > intArray[indexI] ) {
intArray[indexJ] = intArray[indexI];
intArray[indexI] = element;
}
}
if (!sol.num) {
sol.num = intArray[indexI];
sol.count+=1;
} else if (sol.num !== intArray[indexI]) {
sol.num = intArray[indexI];
sol.count+=1;
}
if (sol.count === highest) {
break
}
}
return (sol.count === highest) ? sol.num : undefined;
};