Leetcode 682. Baseball Game
·
Algorithm
제공되는 문자열을 받아 배열의 요소를 모두 더한 값을 리턴하는 문제. 문제 자체는 쉬웠지만 string type의 배열 요소를 number로 변환해주는 작업이 필요했다. 메서드를 사용해 형변환을 해주는 건 불필요하다 생각해 자바스크립트의 특징인 암묵적 형변환을 통해 해결할 수 있었다. * Answer /** * @param {string[]} operations * @return {number} */ var calPoints = function(operations) { const ops = operations; let arr = []; for(let i=0; i number type 변환이 필요. JS의 암묵적 형변환 사용. arr.push(+ops[i]); } } // 완성된 배열을 모두 합산하기 위한..