:

Programming paradigm

10

? , .

Programming paradigm

. , , , , -, . !


?

, . , , .

, , , . . .

, , , . , , .

, . , , , - , ( ).

, , .


?

. . , , .

. , , , ( Haskel ).

. , , - ( JavaScript Python).

, - .


, , , , , .

, . , . .


, , . , ( ), .

, , .

, . :

1- Pour flour in a bowl
2- Pour a couple eggs in the same bowl
3- Pour some milk in the same bowl
4- Mix the ingredients
5- Pour the mix in a mold
6- Cook for 35 minutes
7- Let chill	

, , , 5. :

const nums = [1,4,3,6,7,8,9,2]
const result = []

for (let i = 0; i < nums.length; i++) {
    if (nums[i] > 5) result.push(nums[i])
}

console.log(result) // Output: [ 6, 7, 8, 9 ]	

, , , 5 , 5, .

, .


( ).

, .

. :

function pourIngredients() {
    - Pour flour in a bowl
    - Pour a couple eggs in the same bowl
    - Pour some milk in the same bowl
}

function mixAndTransferToMold() {
    - Mix the ingredients
    - Pour the mix in a mold
}

function cookAndLetChill() {
    - Cook for 35 minutes
    - Let chill
}

pourIngredients()
mixAndTransferToMold()
cookAndLetChill()	

, , , .

. .


.

. , , .

. , , , . . , ( ).

, . , . , .

. , .

const nums = [1,4,3,6,7,8,9,2]
const result = [] // External variable

for (let i = 0; i < nums.length; i++) {
    if (nums[i] > 5) result.push(nums[i])
}

console.log(result) // Output: [ 6, 7, 8, 9 ]	

, , :

const nums = [1,4,3,6,7,8,9,2]

function filterNums() {
    const result = [] // Internal variable

    for (let i = 0; i < nums.length; i++) {
        if (nums[i] > 5) result.push(nums[i])
    }

    return result
}

console.log(filterNums()) // Output: [ 6, 7, 8, 9 ]	

, , . , , . , .


. , , , , .

, . . :

const nums = [1,4,3,6,7,8,9,2]

console.log(nums.filter(num => num > 5)) // Output: [ 6, 7, 8, 9 ]	

, , filter, . , (filter) , (num > 5).

? , . filter, map, reduce sort JavaScript.

/ JS, React. , , :

<button onClick={() => console.log('You clicked me!')}>Click me</button>

(button) , console.log .

JSX (, React) HTML JS. . , . React HTML JS, , .

JSX , , .

, .

, - , for, , , . .


-

- ().

, . () (), .

. - , . , , .

. , ( ) ( ). . , :

// Create the two classes corresponding to each entity
class Cook {
	constructor constructor (name) {
        this.name = name
    }

    mixAndBake() {
        - Mix the ingredients
    	- Pour the mix in a mold
        - Cook for 35 minutes
    }
}

class AssistantCook {
    constructor (name) {
        this.name = name
    }

    pourIngredients() {
        - Pour flour in a bowl
        - Pour a couple eggs in the same bowl
        - Pour some milk in the same bowl
    }
    
    chillTheCake() {
    	- Let chill
    }
}

// Instantiate an object from each class
const Frank = new Cook('Frank')
const Anthony = new AssistantCook('Anthony')

// Call the corresponding methods from each instance
Anthony.pourIngredients()
Frank.mixAndBake()
Anthony.chillTheCake()	

, .


, .

, , , -. , , , , .


50% Merion Academy