+ 10

Challenge - How to find the sum of even digits and odd digits of a given number...?

Example: number = 123 even digit sum = 4{1+3} odd digit sum = 2 Try to find optimal solution..

15th Dec 2017, 1:46 AM
Janagama Prabhakar
Janagama Prabhakar - avatar
16 Respostas
25th Dec 2017, 11:52 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 13
https://code.sololearn.com/ce2T5a3RVu44/?ref=app
15th Dec 2017, 2:16 AM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 12
15th Dec 2017, 11:39 AM
Justine Ogaraku
Justine Ogaraku - avatar
+ 11
what i do take a num n get the first digit (using n%10) check if even then add its value to even number else it is odd add its value to odd number divide n by 10(to get the next digit) repeat using for() until n become 0( no digit to add)
15th Dec 2017, 2:33 AM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
25th Dec 2017, 9:43 AM
LukArToDo
LukArToDo - avatar
+ 9
https://code.sololearn.com/cGYq3dOkjCkN/?ref=app
15th Dec 2017, 10:27 AM
David Ashton
David Ashton - avatar
22nd Dec 2017, 11:17 AM
KĂ€zĂź MrĂźdĂčl HĂžssÀßn
KĂ€zĂź MrĂźdĂčl HĂžssÀßn - avatar
+ 8
Number.prototype.sum = function(chk) { return this.toString().split("").filter((n)=>n%2==chk).reduce((s,n)=>s += +n,0); } https://code.sololearn.com/Wc8sEf86tc7B/?ref=app
15th Dec 2017, 2:06 AM
CalviŐČ
CalviŐČ - avatar
+ 8
Java, using String to int conversion: https://code.sololearn.com/cdtd2WH451wd/?ref=app Java, using bitwise operation: https://code.sololearn.com/cDRQkynQ1b1K/?ref=app
15th Dec 2017, 3:59 AM
Boris Batinkov
Boris Batinkov - avatar
+ 7
nice..... is there any optimal logic for this?
15th Dec 2017, 2:22 AM
Janagama Prabhakar
Janagama Prabhakar - avatar
+ 5
@Natanaelk This is spam please delete it !!!
17th Dec 2017, 10:49 PM
James16
James16 - avatar
16th Dec 2017, 6:19 PM
Hiroki Masuda
Hiroki Masuda - avatar