forked from M3-Academy/challenge-algorithms-v2.0
refactor: padroniza formatação do código #2
@ -1,10 +1,11 @@
|
|||||||
export function isPrime(value) {
|
export function isPrime(value) {
|
||||||
if (value <= 1) return false;
|
if (value <= 1) return false;
|
||||||
|
|
||||||
for (let divisor = 2; divisor <= Math.sqrt(value); divisor++) {
|
let valueSqrt = Math.sqrt(value);
|
||||||
if (value % divisor === 0) {
|
|
||||||
return false
|
for (let divisor = 2; divisor <= valueSqrt; divisor++) {
|
||||||
}
|
if (value % divisor === 0) return false;
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
|
return true;
|
||||||
}
|
}
|
@ -1,8 +1,8 @@
|
|||||||
export function isAnagram(word1, word2) {
|
export function isAnagram(word1, word2) {
|
||||||
if (word1.length != word2.length) return false
|
if (word1.length != word2.length) return false;
|
||||||
|
|
||||||
let sortedWord1Array = [...word1.toLowerCase()].sort()
|
let sortedWord1Array = [...word1.toLowerCase()].sort();
|
||||||
let sortedWord2Array = [...word2.toLowerCase()].sort()
|
let sortedWord2Array = [...word2.toLowerCase()].sort();
|
||||||
|
|
||||||
return (sortedWord1Array.join('') === sortedWord2Array.join(''));
|
return (sortedWord1Array.join('') === sortedWord2Array.join(''));
|
||||||
}
|
}
|
@ -1,12 +1,11 @@
|
|||||||
export function longestWords(words) {
|
export function longestWords(words) {
|
||||||
|
|
||||||
let sortedWords = words.sort((a, b) => b.length - a.length);
|
let sortedWords = words.sort((a, b) => b.length - a.length);
|
||||||
let maxLength = sortedWords[0].length
|
let maxLength = sortedWords[0].length;
|
||||||
let longestWords = []
|
let longestWords = [];
|
||||||
|
|
||||||
for (let word of sortedWords) {
|
for (let word of sortedWords) {
|
||||||
if(word.length != maxLength) break;
|
if(word.length != maxLength) break;
|
||||||
longestWords.push(word)
|
longestWords.push(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
return longestWords;
|
return longestWords;
|
||||||
|
Loading…
Reference in New Issue
Block a user