Skip to content

This page contains a variety of application formulas that are used in various projects that we develop frontend programmers ♥

Notifications You must be signed in to change notification settings

khadem-mh/formulas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 

Repository files navigation

Hi👋

This page contains a variety of application formulas that are used in various projects that we develop frontend programmers ♥



randomChooseItemFromArray.js

const randomChooseItemFromArray = (arr, randomCount) => {
    const shuffled = arr.sort(() => .5 - Math.random())
    return shuffled.slice(0, randomCount)
}

scrollHorizontal.js

let customScroll = document.getElementById('scroll')

const scrollHorizontal = () => {
    let scrollPercent = window.scrollY / (document.body.clientHeight - window.innerHeight)
    let scrollPercentRoundede = Math.round(scrollPercent * 100)
    customScroll.style.width = scrollPercentRoundede + '%'
}

window.addEventListener('scroll', scrollHorizontal)

concatinationArray.js

let arr1 = [1, 2, 3, 4, 5]
let arr2 = [6, 7, 8, 9, 10]

let concatNumsArray = [...arr1, ...arr2]

sortingArray.js

let arr1 = [2, 6, 1, 4, 7, 0, 3, 9, 10, 5, 8]
let numsArrSort = arr1.sort((a, b) => { return a - b })

determinationCountNumber.js

let arr1 = [2, 6, 1, 4, 7, 0, 3, 7, 9, 10, 5, 8, 5, 2]

let numberReapet = numsArrSort.reduce((prev, current) => {
    return { ...prev, [current]: (prev[current] || 0) + 1 }
}, {})

for (let num in numberReapet) {
    nums += ` ${num} `
    console.log(nums);
}

findMaxNumber.js

let arr1 = [2, 6, 1, 4, 7, 0, 3, 7, 9, 10, 5, 8, 5, 2]

let maxNumber = arr1.reduce((prevNum, currentNum) => {
if (prevNum < currentNum) return currentNum
else return prevNum
}, 0)

findMinNumber.js

let arr1 = [2, 6, 1, 4, 7, 0, 3, 7, 9, 10, 5, 8, 5, 2]

let minNumber = arr1.reduce((prevNum, currentNum) => {
if (prevNum > currentNum) return currentNum
else return prevNum
}, 0)

getOutAreaBox.js

let getPositionElem = boxElem.getBoundingClientRect()

if (
    event.clientY < getPositionElem.top ||
    event.clientY > (getPositionElem.top + getPositionElem.height) ||
    event.clientX > (getPositionElem.left + getPositionElem.width) ||
    event.clientX < getPositionElem.left
) {
    console.log('outside');
}

About

This page contains a variety of application formulas that are used in various projects that we develop frontend programmers ♥

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published