educative.io

Educative

Putting it all together

Hi,
I tried but failed in all 3 practices. I is frustrating not knowing the solutions.
I would like to get the solution of each test please.

Thanks,
Masha


Type your question above this line.

Course: https://www.educative.io/collection/5679346740101120/5720605454237696
Lesson: https://www.educative.io/collection/page/5679346740101120/5720605454237696/5647906690301952

Hello @masha

Following are the solutions for the 3 practices in order:

function double(arr) {
    let newArr = [];
    for(let i = 0; i < arr.length; i++){
        newArr.push(arr[i] * 2);
    }
    return newArr;
}
function getFullName(obj) {
    return obj['firstName'] + ' ' + obj['lastName'];
}
function addValues(obj) {
    let sum = 0;
    for (let key in obj) {
        sum = sum + obj[key];
    }
    return sum;
}

Hope this helps!