Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

reduction of complexity numbers procedure

I’m looking for a solution to my problem

if I have numbers

var first = 14:1
var next = 13:8

therefore, the console should give a result

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

console.log(first_result)  // 141
console.log(next_result)  // 141

and I want the numbers counted like 141 in the result to be

simply if there is an example

13:8 if both digits are the last, 3 and 8 are bigger than ten, then turn the tens and turn and insert into the previous number and leave the rest at the end

so 13:8 becomes 141

>Solution :

If you are starting with strings, then you just simply split the string on : to get your 2 numbers.

To get the last digit, you can simply use x % 10. Then just add the numbers and see what happens.

let value = '13:8',
    nums = value.split(':').map(Number),
    last_digits = nums.map(x => x % 10),
    // or last_digits.reduce((x,y) => x+y, 0)
    sum = last_digits[0] + last_digits[1],
    result;

if (sum > 10) {
    nums[0]++;
    nums[1] = sum - 10;  // or, probably sum % 10
}

result = nums.join('');
console.log(result);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading