mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2026-03-13 15:21:15 +08:00
Fix/code smells (#1338)
* ♻️ refactor: improving and fixing some code * Updated Documentation in README.md * ♻️ refactor: improving isLeapYear * 🐛 chore: back changes * 🐛 fix: using reduce instead forEach * 🐛 fix: using reduce instead forEach * 🐛 fix: removing duplicated code * 🐛 chore: removing .js --------- Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@@ -14,9 +14,5 @@
|
||||
* @returns {boolean} true if this is a leap year, false otherwise.
|
||||
*/
|
||||
export const isLeapYear = (year) => {
|
||||
if (year % 400 === 0) return true
|
||||
if (year % 100 === 0) return false
|
||||
if (year % 4 === 0) return true
|
||||
|
||||
return false
|
||||
return ((year % 400) === 0) || (((year % 100) !== 0) && ((year % 4) === 0))
|
||||
}
|
||||
|
||||
@@ -20,12 +20,9 @@ const matrixCheck = (matrix) => {
|
||||
// tests to see if the matrices have a like side, i.e. the row length on the first matrix matches the column length on the second matrix, or vice versa.
|
||||
const twoMatricesCheck = (first, second) => {
|
||||
const [firstRowLength, secondRowLength, firstColLength, secondColLength] = [first.length, second.length, matrixCheck(first), matrixCheck(second)]
|
||||
if (firstRowLength !== secondColLength || secondRowLength !== firstColLength) {
|
||||
// These matrices do not have a common side
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
|
||||
// These matrices do not have a common side
|
||||
return firstRowLength === secondColLength && secondRowLength === firstColLength
|
||||
}
|
||||
|
||||
// returns an empty array that has the same number of rows as the left matrix being multiplied.
|
||||
|
||||
@@ -41,8 +41,7 @@ function integralEvaluation (N, a, b, func) {
|
||||
|
||||
// Calculate the integral
|
||||
let result = h
|
||||
temp = 0
|
||||
for (let i = 0; i < pointsArray.length; i++) temp += pointsArray[i]
|
||||
temp = pointsArray.reduce((acc, currValue) => acc + currValue, 0)
|
||||
|
||||
result *= temp
|
||||
|
||||
|
||||
@@ -54,8 +54,7 @@ function integralEvaluation (N, a, b, func) {
|
||||
|
||||
// Calculate the integral
|
||||
let result = h / 3
|
||||
temp = 0
|
||||
for (let i = 0; i < pointsArray.length; i++) temp += pointsArray[i]
|
||||
temp = pointsArray.reduce((acc, currValue) => acc + currValue, 0)
|
||||
|
||||
result *= temp
|
||||
|
||||
|
||||
Reference in New Issue
Block a user