Sort by

recency

|

445 Discussions

|

  • + 0 comments

    test case 2 is wrong!

    input is [14 25 36 47 58 69 70 81 92], but expected output is [28 75 72 141 116 207 140 243 184]

    I think the real answer is [42, 50, 108, 94, 174, 138, 210, 162, 276]

    check it please

  • + 0 comments
    function modifyArray(nums) {
      const transform = x => x % 2 == 0 ? x * 2 : x * 3;
      return nums.map(transform);
    }
    
  • + 0 comments
    function modifyArray(nums) {
        const arr = nums.map((e)=>{
           if(e%2==0){
            return e*2;
           } else{
            return e*3;
           }
        });
        return arr;
    }
    
  • + 0 comments
    const modifyArray = (nums) => {
        return nums.map((num)=>{return (num%2 === 0)?(num*2):(num*3)})
    }
    

    this is the simpliest way to do it , where map() creates a new array from calling a function for every array element and does not change the original array. then just return the new array for modifyArray function.

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