Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6794e9d

Browse files
Merge pull request neetcode-gh#2815 from chetannada/ltc-2160-js
Create 2160-minimum-sum-of-four-digit-number-after-splitting-digits.js
2 parents f3b2304 + b2975c9 commit 6794e9d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @param {number} num
3+
* @return {number}
4+
*/
5+
var minimumSum = function (num) {
6+
let str = String(num).split("").sort(); // intialize str and split the num using String(), split() and sort()
7+
return parseInt(str[0] + str[2]) + parseInt(str[1] + str[3]); // return sum of 1st, 3rd and 2nd, 4th string digit and convert into num using parseInt
8+
};

0 commit comments

Comments
 (0)