fix: standard style issues

This commit is contained in:
Rak Laptudirm
2021-10-21 22:59:56 +05:30
parent 65916747d8
commit 22ce7603e4
7 changed files with 20 additions and 56 deletions

View File

@ -1,5 +1,5 @@
const pad = (num, padlen) => {
var pad = new Array(1 + padlen).join(0)
const pad = new Array(1 + padlen).join(0)
return (pad + num).slice(-pad.length)
}

View File

@ -40,7 +40,7 @@ const orders = [
function decimalToRoman (num) {
let roman = ''
for (var symbol of orders) {
for (const symbol of orders) {
while (num >= values[symbol]) {
roman += symbol
num -= values[symbol]

View File

@ -1,18 +1,16 @@
function hexToInt (hexNum) {
const numArr = hexNum.split('') // converts number to array
numArr.map((item, index) => {
if (!(item > 0)) {
return numArr.map((item, index) => {
switch (item) {
case 'A': return (numArr[index] = 10)
case 'B': return (numArr[index] = 11)
case 'C': return (numArr[index] = 12)
case 'D': return (numArr[index] = 13)
case 'E': return (numArr[index] = 14)
case 'F': return (numArr[index] = 15)
case 'A': return 10
case 'B': return 11
case 'C': return 12
case 'D': return 13
case 'E': return 14
case 'F': return 15
default: return parseInt(item)
}
} else numArr[index] = parseInt(item)
})
return numArr // returns an array only with integer numbers
}
function hexToDecimal (hexNum) {
@ -23,9 +21,3 @@ function hexToDecimal (hexNum) {
}
export { hexToInt, hexToDecimal }
// > hexToDecimal('5DE9A'))
// 384666
// > hexToDecimal('3D'))
// 61

View File

@ -33,9 +33,7 @@ class CircularQueue {
}
const y = this.queue[this.front]
this.queue[this.front] = '*'
if (this.checkSingleelement()) {
} else {
if (!this.checkSingleelement()) {
if (this.front === this.maxLength) this.front = 1
else {
this.front += 1

View File

@ -1,26 +0,0 @@
// https://projecteuler.net/problem=7
// My approach does not use the Sieve of Eratosthenes but that is another common way to approach this problem. Sieve of Atkin is another possibility as well.
export const calculatePrime = (num = 10001, primes = [2, 3, 5, 7, 11, 13]) => {
// Calculate each next prime by checking each number to see what it's divisible by
let count = primes.length // count number of primes calculated
let current = primes[count - 1] + 1 // current number being assessed if prime
while (count < num) { // repeat while we haven't reached goal number of primes
// go through each prime and see if divisible by the previous primes
let prime = false
primes.some((n, i) => {
if (current % n === 0) {
return true
}
if (i === count - 1) {
prime = true
}
})
if (prime) { // if prime, add to prime list and increment count
primes.push(current)
count += 1
}
current += 1
}
return primes[num - 1]
}