문제 링크 : Crawler Log Folder
/**
* @param {string[]} logs
* @return {number}
*/
var minOperations = function(logs) {
let cnt = 0
logs.forEach(e => {
if(e === '../') {
cnt - 1 < 0 ? cnt = 0 : cnt -= 1
}else {
if(e !== './') {
cnt += 1
}
}
})
return cnt
};
/**
* @param {string[]} logs
* @return {number}
*/
var minOperations = function(logs) {
return logs.reduce( (cnt, curEl) => {
if(curEl === '../') {
cnt - 1 < 0 ? cnt = 0 : cnt -= 1
}else {
if(curEl !== './') {
cnt += 1
}
}
return cnt
}, 0)
};