Ad

The task is reaaaaly easy,you're given an array of different numbers, return the sum of even numbers.If there is no even numbers or there is empty array,return false.

function SumEven(arr){
    let sum=0;
    
    for(let i=0;i<arr.length;i++){
        if(arr[i]%2===0) sum+=arr[i];
    }
    if(sum===0 || arr.length===0)
    return false
    else
    return sum;
}

You are given an array containing characters, numbers, and null values. The task is to return a new array where the elements are ordered as follows: null values first, followed by numbers (sorted in ascending order), and characters (sorted in alphabetical order). All elements should be sorted within their respective categories.

function falsyNumberChar(arr) {
  let falsy = [],
    number = [],
    char = [];
  arr.forEach((element) => {
    if (element === null) falsy.push(element);
    else if (Number(element)) number.push(element);
    else if (String(element)) char.push(element);
  });
  number.sort();
  char.sort();
  return [...falsy, ...number, ...char];
}
Code
Diff
  • function sumNechet(a, b) {
      let sum = 0;
      while (a <= b) {
        a % 2 !== 0 ? (sum += a) : null;
        a++;
      }
      return sum;
    }
    • sumNechet = (a, b) => (b/2).toFixed()**2;
    • function sumNechet(a, b) {
    • let sum = 0;
    • while (a <= b) {
    • a % 2 !== 0 ? (sum += a) : null;
    • a++;
    • }
    • return sum;
    • }