Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

sum of digits in a whole number javascript

sum = 0;
while (value) {
    sum += value % 10;
    value = Math.floor(value / 10);
}
Comment

javascript sum digits in string of numbers

const sumDigits = num => num.toString().split('').map(Number).reduce((a,b) => a + b);
//usage: mySum=sumDigits(myNum); console.log(sumDigits(1234)) output: 10
Comment

javascript Program for Sum of the digits of a given number

<script>
 
// Javascript program to compute sum of digits in
// number.
 
/* Function to get sum of digits */
function getSum(n)
{
    var sum = 0;
    while (n != 0) {
        sum = sum + n % 10;
        n = parseInt(n / 10);
    }
    return sum;
}
 
// Driver code
var n = 687;
document.write(getSum(n));
 
</script>
Comment

js sum digits

// Sum of all the digits of a number in Javascript
const num = 1245,
    sum = num
        .toString()
        .split('')
        .map(Number)
        .reduce((a,b) => a + b);
console.log(sum); // 12
Comment

PREVIOUS NEXT
Code Example
Javascript :: sum of odd numbers in an array javascript without loop 
Javascript :: javascript regex exact match 
Javascript :: is digit javascript 
Javascript :: how to check if the element exist in the parent element javascript 
Javascript :: capitalize all letters jquery 
Javascript :: jest run specific test 
Javascript :: javascript regex stop at first match 
Javascript :: calling angular component method in service 
Javascript :: Hide angular element on button click 
Javascript :: js remove key from object 
Javascript :: c# razor for loop javascript 
Javascript :: vue change specific params/query 
Javascript :: javascript promise example basic 
Javascript :: object to map javascript 
Javascript :: react.createelement 
Javascript :: sveltekit tailwind 
Javascript :: slice string js 
Javascript :: remove all sign that is not a-b in string js 
Javascript :: from 0 or 1 to boolean javascript 
Javascript :: onclick arrow function javascript 
Javascript :: Comment intégrer font awesome et bootstrap dans angular 13 
Javascript :: stopwatch with javascript 
Javascript :: how to swap two elements in an array javascript 
Javascript :: convert json to array 
Javascript :: 7) Change cursor:pointer at checkboxes in java script 
Javascript :: compare objects 
Javascript :: ** javascript Exponentiation 
Javascript :: pattern alphabet and space 
Javascript :: export javascript 
Javascript :: Missing script: "start" react 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =