sum of digits of a number in javascript

Define a function that a number n as parameter and returns the sum of the
numbers from 1 to n Javascript Program

let n=20; function findSum(n) { let sum = 0; for (let x = 1; x <= n; x++) sum =… Read More

Given a string remove all + present together in the string. Javascript Program

Input string ='a+++b++c+'; Output String=a+b+c+ Source Code let str='a+++b++c+'; let outStr=''; let len=str.length; for(let i=0;i<len;i++) { if(str[i]=='+'&&str[i+1]=='+') { outStr=outStr+''; }… Read More

Given a string str, create a string consisting of all the non-alphabets and non-digits.

JavaScript code let str='q#w2@B**g'; let len=str.length; let alpha=''; let alpha1=''; let rest=''; let digits=''; for(let i=0;i<len;i++) { if(str[i]>='a'&&str[i]<='z') { alpha=alpha+str[i];… Read More

This website uses cookies.