diff --git a/JinHaLim/Easy/solution_1281.js b/JinHaLim/Easy/solution_1281.js new file mode 100644 index 0000000..3a5ec8c --- /dev/null +++ b/JinHaLim/Easy/solution_1281.js @@ -0,0 +1,13 @@ +/** + * @param {number} n + * @return {number} + */ +var subtractProductAndSum = function(n) { + const digit = n.toString().split('').reduce((acc,curr) => { + acc[0] *= curr; + acc[1] += +curr; + return acc; + },[1,0]); + return digit[0] - digit[1]; +}; +console.log(subtractProductAndSum(234)) \ No newline at end of file diff --git a/JinHaLim/Easy/solution_1342.js b/JinHaLim/Easy/solution_1342.js new file mode 100644 index 0000000..c863f12 --- /dev/null +++ b/JinHaLim/Easy/solution_1342.js @@ -0,0 +1,18 @@ +/** + * @param {number} num + * @return {number} + */ +var numberOfSteps = function(num) { + let count = 0; + while (num !== 0) { + count += 1; + if (num % 2 === 0) { + num = num / 2; + } + else{ + num -= 1; + } + } + return count; +}; +console.log(numberOfSteps(14)) \ No newline at end of file diff --git a/JinHaLim/Easy/solution_1720.js b/JinHaLim/Easy/solution_1720.js new file mode 100644 index 0000000..924abd7 --- /dev/null +++ b/JinHaLim/Easy/solution_1720.js @@ -0,0 +1,14 @@ +/** + * @param {number[]} encoded + * @param {number} first + * @return {number[]} + */ +var decode = function(encoded, first) { + let arr = new Array(encoded.length + 1); + arr[0] = first; + encoded.forEach((v,i) => { + arr[i+1] = v ^ arr[i]; + }); + return arr; +}; +console.log(decode([1,2,3],1)) \ No newline at end of file