Sort by

recency

|

440 Discussions

|

  • + 0 comments
    function modifyArray(nums) {
        return nums.map(n => {
            return n * (2 + n%2)
        })
    }
    
  • + 0 comments

    In JS

    function modifyArray(nums) {
        const res = nums.map((val) => {
      if (val % 2 == 0) {
        return val * 2;
      } else {
        return val * 3;
      }
    });
    
    return res;
    
    }
    
  • + 0 comments

    Managed to fit in one line:

    function modifyArray(nums) {
        return nums.map(n => n % 2 ? n * 3 : n * 2);
    }
    
  • + 0 comments

    function modifyArray(nums) { let newArr = nums.map(x => x % 2 === 0 ? x * 2 : x * 3); return newArr; }

  • + 0 comments
          function modifyArray(nums) {
      for (let i = 0; i < nums.length; i++) {
        if (nums[i] % 2 === 0) {
          nums[i] = nums[i] * 2;
        } else {
          nums[i] = nums[i] * 3;
        }
      }
      return nums;
    }