-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
75 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { describe, expect, test } from "@jest/globals"; | ||
|
||
describe("merginIntervals", () => { | ||
const isPrime = (number: number) => { | ||
if (number <= 1) return false; | ||
if (number <= 3) return true; | ||
return Array.from({ length: number - 2 }).every((_, index) => { | ||
const divider = index + 2; | ||
if (number % divider === 0) { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
}; | ||
|
||
test("no arg", async () => { | ||
expect(isPrime(0)).toBe(false); | ||
// expect(isPrime(1)).toBe(false); | ||
// expect(isPrime(2)).toBe(true); | ||
// expect(isPrime(3)).toBe(true); | ||
// expect(isPrime(23)).toBe(true); | ||
// expect(isPrime(22)).toBe(false); | ||
// expect(isPrime(21)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { describe, expect, test } from "@jest/globals"; | ||
|
||
describe("validPalindrome", () => { | ||
function validPalindrome(s: string, MAX_DIFFS = 1): boolean { | ||
const isPalindrome = (sub: string, depth = 0): boolean => { | ||
if (depth > 0) console.log(sub); | ||
let leftPointer = 0; | ||
let rightPointer = sub.length - 1; | ||
|
||
while (leftPointer < rightPointer) { | ||
const leftChar = sub[leftPointer]; | ||
const rightChar = sub[rightPointer]; | ||
if (leftChar !== rightChar) | ||
return depth < MAX_DIFFS | ||
? isPalindrome(sub.slice(leftPointer, rightPointer), depth + 1) || | ||
isPalindrome( | ||
sub.slice(leftPointer + 1, rightPointer + 1), | ||
depth + 1 | ||
) | ||
: false; | ||
|
||
leftPointer++; | ||
rightPointer--; | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
return isPalindrome(s); | ||
} | ||
|
||
test("no arg", async () => { | ||
expect(validPalindrome("12", 0)).toBe(true); | ||
}); | ||
}); |