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