Загрузка данных





// ------------функциональные выражения________________
// function standartSun (a, b) {
//     return a+b
// }





// function processUser (name, callback)


// цикл на 20 итераций
const arr = []
for (let i = 0; i < 20 ; i ++) { //от 0 до 19 итераций
    arr.push(Math.floor(Math.random() * 100) + 1)
}


// console.log(arr);



//2 массива
let lessThan50  = [];
let moreThan50 = [];

// lessThan50 = function (array) {
//     for (let i = 0; i < array.length; i ++) {
//         if (array[i] > 50 ) {
//             delete array[i]
//             array[i] = "deleted"
//         }
//     }
//     return array
// }
// lessThan50 = lessThan50 (arr)
// console.log(lessThan50);


// lessThan50 = function (array) {
//     let newArr = []
//     for (let i = 0; i < array.length; i ++) {
//         if (array[i] > 50 ) {
//             lessThan50.push() //ошибкак так как не  инициализировано функ-е выражение
//         } else {
//             moreThan50.push()
//         }
//     }
//     return array
// }
// lessThan50 = lessThan50 (arr)
// console.log(lessThan50);


lessThan50 = function (array) {
    let newArr = []
    for (let i = 0; i < array.length; i ++) {
        if (array[i] < 50 ) {
            newArr.push(array[i])  
        } 
    }
    return newArr
}

moreThan50 = function (array) {
    let newArr = []
    for (let i = 0; i < array.length; i ++) {
        if (array[i] > 50 ) {
            newArr.push(array[i])  
        } 
    }
    return newArr
}
// console.log(lessThan50(arr));


const showArray = (less, more) => { 
    console.log(less);
    console.log(more);
}
showArray(lessThan50(arr), moreThan50(arr))


function modernization (less, more, upgrade, downgrade) {
    let isLess = true, isMore = false
    for (let i = 0; i < less.length; i ++) {
        if (less[i] > 50 && !isLess) {
            isLess = false
            break
        }
    }
    
    if (isLess ) {
        upgrade(less)
    }
    if (isMore) {
        downgrade(more)
    }
    console.log(less);
    console.log(more); 
    
}

function upgradeArray (array) {
    for (let i = 0; i < array.length; i++) {
        array[i] *= 1.2
        
    }
    return array
}
function downArray (array) {
    for (let i = 0; i < array.length; i++) {
        array[i] *= 0.8
        
    }
    return array
}

console.log(modernization(lessThan50(arr), moreThan50(arr), upgradeArray, downArray)) 







const voidArr = [];
function fillArray (voidArr) {
    let currentValue = voidArr.length > 0
        ? voidArr [0]
        : 0

    for (let i = 0; i < 50; i++) {
        console.log(i % 2 == 0);
        currentValue = Math.floor(Math.random() * 100) + 1

        if ( i % 2 == 0) {
            currentValue = "$" + currentValue;        
        } else currentValue += "RUB"

        voidArr.push(currentValue)

    }   
        
}

fillArray(voidArr);
console.log(voidArr);










function converToUsd (rub) {
    return rub / 80
}

function convertToRub (usd) {
    return usd * 80
}

function exchange (cash, convertUsd, convertRub) {
    for (let m = 0; m < cash; m++) {
        if (arr[m][0] == "$") {
            arr[m] = convertRub()
        } else arr [m]
        
    }
}