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 :: how to delete object properties in javascript 
Javascript :: json vs xml 
Javascript :: vue font awesome icons 
Javascript :: jquery ajax true false as boolean value 
Javascript :: how to return argument in javascript 
Javascript :: javascript close app phonegap 
Javascript :: javascript constant variable 
Javascript :: nestjs swagger 
Javascript :: knex.js migration create 
Javascript :: array check in javascript 
Javascript :: javascript for...of with Strings 
Javascript :: JavaScript super() keyword 
Javascript :: subset in js 
Javascript :: mysql json 
Javascript :: Generate a Random Integer 
Javascript :: check empty object javascript 
Javascript :: random trong js 
Javascript :: how to install exact package lock version in package-lock.json 
Javascript :: nginx reverse proxy redirect 
Javascript :: every() method 
Javascript :: toast success 
Javascript :: JavaScript then() method 
Javascript :: how to upload image in react js 
Javascript :: export function node js 
Javascript :: js append zeros 
Javascript :: jquery get textarea value 
Javascript :: clearinterval javascript 
Javascript :: import all images from folder react 
Javascript :: Slice and Splice -Javascript 
Javascript :: clone an object in javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =