diff --git a/technical-fundamentals/coding/problems/01_isUnique.ts b/technical-fundamentals/coding/problems/01_isUnique.ts index 07f432b1..6bceec1e 100644 --- a/technical-fundamentals/coding/problems/01_isUnique.ts +++ b/technical-fundamentals/coding/problems/01_isUnique.ts @@ -3,4 +3,39 @@ // Implement an algorithm to determine if a string has all unique characters. // What if you cannot use additional data structures? -export default function isUnique(str: string): boolean {} +export default function isUnique(str: string): boolean { + + const sorted = str.split("").sort().join(""); + let prev = null; + for(let i = 0; i < sorted.length; i++) { + if(sorted[i] === prev) return false; + prev = sorted[i]; + } + return true; + +} + +export function tsSimple(str: string){ + const map: Record = {}; + for(let i = 0; i < str.length; i++) { + if(map[str[i]]) { + return false; + } else{ + map[str[i]] = true; + } + } + return true; +} + +const pureJSSimple = function(str){ + const map = {}; + for(let i = 0; i < str.length; i++) { + console.log(map[str[i]]); + if(map[str[i]] === true) { + return false; + } else{ + map[str[i]] = true; + } + } + return true; +} diff --git a/technical-fundamentals/coding/problems/02_checkPermutations.ts b/technical-fundamentals/coding/problems/02_checkPermutations.ts index 56deb0f0..9f2d556e 100644 --- a/technical-fundamentals/coding/problems/02_checkPermutations.ts +++ b/technical-fundamentals/coding/problems/02_checkPermutations.ts @@ -2,4 +2,34 @@ // Given two strings, write a method to decide if one is a permutation of the other. -export default function checkPermutations(s1: string, s2: string): boolean {} +//O(n) -better but with more space complexity- +export default function checkPermutations(s1: string, s2: string): boolean { + const letterSet: Set = new Set(); + const letterMap: Record = {}; + + for (let i = 0; i < s1.length; i++) { + letterSet.add(s1[i]); + if(letterMap[s1[i]]) { + letterMap[s1[i]]++; + } else { + letterMap[s1[i]] = 1; + } + } + + for (let i = 0; i < s2.length; i++) { + if(!letterMap[s2[i]] || letterMap[s2[i]] === 0) { + return false; + } + if(letterMap[s2[i]] === 1) { + letterSet.delete(s2[i]); + } + letterMap[s2[i]]--; + } + + return letterSet.size === 0; +} + +//simpler solution sorting O(nlogn) +export function checkSimple(s1: string, s2: string): boolean{ + return s1.split('').sort().join('') === s2.split('').sort().join(''); +} \ No newline at end of file diff --git a/technical-fundamentals/coding/problems/03_urlify.ts b/technical-fundamentals/coding/problems/03_urlify.ts index ca989b83..e7f75751 100644 --- a/technical-fundamentals/coding/problems/03_urlify.ts +++ b/technical-fundamentals/coding/problems/03_urlify.ts @@ -4,6 +4,29 @@ // You may assume that the string has sufficient space at the end to hold the additional characters, // and that you are given the "true" length of the string. -export default function URLify (s1 : string): string { +export default function URLify (s1 : string[]): string[] { + + let next = s1[s1.length - 1]; + let index: number = s1.length - 1; + while(next === ' '){ + index--; + next = s1[index]; + } + + let pointer = s1.length - 1; + + for(let i = index; i >= 0; i--){ + if(s1[i] !== ' '){ + s1[pointer] = s1[i]; + pointer--; + } else { + s1[pointer] = '0'; + s1[pointer - 1] = '2'; + s1[pointer - 2] = '%'; + pointer -= 3; + } + } + + return s1; } \ No newline at end of file diff --git a/technical-fundamentals/coding/problems/04_palindromePermutation.ts b/technical-fundamentals/coding/problems/04_palindromePermutation.ts index d80c9217..fe550bf7 100644 --- a/technical-fundamentals/coding/problems/04_palindromePermutation.ts +++ b/technical-fundamentals/coding/problems/04_palindromePermutation.ts @@ -11,4 +11,29 @@ export default function palindromePermutation (str: string): boolean { + //worst case time complexity = O(2n) -> O(n) + + let charMap: Map = new Map(); + for (let i = 0; i < str.length; i++) { + if(str[i] === ' ') continue; + const currChar = str[i].toLowerCase(); + if(charMap.has(currChar)){ + charMap.set(currChar, charMap.get(currChar) + 1); + } else { + charMap.set(currChar, 1); + } + } + + let oddValues: number = 0; + + for(const [_, number] of charMap){ + if(number % 2 !== 0 && oddValues > 0) { + return false; + } else if(number % 2 !== 0){ + oddValues++; + } + } + + return true; + } \ No newline at end of file diff --git a/technical-fundamentals/coding/problems/05_oneAway.ts b/technical-fundamentals/coding/problems/05_oneAway.ts index 79c9a12d..ad31ae84 100644 --- a/technical-fundamentals/coding/problems/05_oneAway.ts +++ b/technical-fundamentals/coding/problems/05_oneAway.ts @@ -5,5 +5,28 @@ // Given two strings, write a function to check if they are one edit (or zero edits) away. export default function isOneAway(str1: string, str2: string): boolean { - + + if(str1.length > str2.length + 2 || str1.length < str2.length - 2) return false; + if(str1 === str2) return true; + + for(let i = 0; i < str1.length; i++){ + if(str1[i] !== str2[i]){ + return equalsWithDelete(str1.substring(i), str2.substring(i)) || + equalsWithInsert(str1.substring(i), str2.substring(i)) || + equalsWithReplace(str1.substring(i), str2.substring(i)); + } + } + + return true; + +} + +export function equalsWithDelete(str1: string, str2: string): boolean { + return str1.substring(1) === str2 || str1 === str2.substring(1); +} +export function equalsWithInsert(str1: string, str2: string): boolean { + return str2[0] + str1 === str2 || str1[0] + str2 === str1; +} +export function equalsWithReplace(str1: string, str2: string): boolean { + return str2[0] + str1.substring(1) === str2 || str1[0] + str2.substring(1) === str1; } diff --git a/technical-fundamentals/coding/problems/06_stringCompression.ts b/technical-fundamentals/coding/problems/06_stringCompression.ts index 525ce40d..996d9d1c 100644 --- a/technical-fundamentals/coding/problems/06_stringCompression.ts +++ b/technical-fundamentals/coding/problems/06_stringCompression.ts @@ -7,5 +7,22 @@ // You can assume the string has only uppercase and lowercase letters (a - z). export default function stringCompression (str: string) : string { + let counter: number = 0; + let prev: string = ''; + let output: string = ''; + for(let i: number = 0; i < str.length; i++){ + if(str[i] !== prev){ + if(prev != ''){ + output += prev + counter.toString(); + counter = 0; + } + prev = str[i]; + } + counter++; + } + + output += prev + counter.toString(); + + return output.length < str.length ? output : str; } \ No newline at end of file diff --git a/technical-fundamentals/coding/problems/07_rotateMatrix.ts b/technical-fundamentals/coding/problems/07_rotateMatrix.ts index 875d0841..9f47f1cc 100644 --- a/technical-fundamentals/coding/problems/07_rotateMatrix.ts +++ b/technical-fundamentals/coding/problems/07_rotateMatrix.ts @@ -7,4 +7,16 @@ type Matrix = number[][] export default function rotateMatrix (matrix: Matrix) { -} \ No newline at end of file + for(let i = 0; i < matrix.length; i++){ + for(let j = i; j < matrix.length; j++){ + const aux = matrix[i][j]; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = aux; + } + } + + for(let i = 0; i < matrix.length; i++){ + matrix[i].reverse(); + } + +} diff --git a/technical-fundamentals/coding/problems/08_zeroMatrix.ts b/technical-fundamentals/coding/problems/08_zeroMatrix.ts index 5bf6941d..5d4d007f 100644 --- a/technical-fundamentals/coding/problems/08_zeroMatrix.ts +++ b/technical-fundamentals/coding/problems/08_zeroMatrix.ts @@ -6,4 +6,29 @@ type Matrix = number[][] export default function zeroMatrix (matrix: Matrix) { + let setRow: Set = new Set(); + let setCol: Set = new Set(); + for(let i = 0; i < matrix[0].length; i++){ + for(let j= 0; j < matrix.length; j++){ + if(matrix[i][j] === 0 && !setRow.has(i) && !setCol.has(j)){ + fillRow(i, matrix[0].length, matrix); + fillCol(j, matrix.length, matrix); + setRow.add(i); + setCol.add(j); + } + } + } + +} + +export function fillCol(col:number, mlength: number, matrix: Matrix){ + for(let i = 0; i < mlength; i++){ + matrix[i][col] = 0; + } +} + +export function fillRow(row:number, mlength: number, matrix: Matrix){ + for(let j = 0; j < mlength; j++){ + matrix[row][j] = 0; + } } \ No newline at end of file diff --git a/technical-fundamentals/coding/problems/09_stringRotation.ts b/technical-fundamentals/coding/problems/09_stringRotation.ts index afc900e0..385fbdf6 100644 --- a/technical-fundamentals/coding/problems/09_stringRotation.ts +++ b/technical-fundamentals/coding/problems/09_stringRotation.ts @@ -6,4 +6,24 @@ import { isSubstring } from "./__utils__/strings" // Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to isSubstring. // [e.g., "waterbottle" is a rotation of 'erbottlewat") -export default function stringRotation(s1: string, s2: string): boolean {} +export default function stringRotation(s1: string, s2: string): boolean { + + if(s1.length != s2.length) return false; + + let stringEnd = ""; + + for(let i = 0; i < s1.length; i++){ + if(s2[i] !== s1[0]){ + stringEnd += s2[i]; + } else { + if(s2.substring(i) + stringEnd === s1){ + return true; + } else { + stringEnd += s2[i]; + } + } + } + + return false; + +} diff --git a/technical-fundamentals/coding/problems/10_LinkedList.ts b/technical-fundamentals/coding/problems/10_LinkedList.ts index a88e026f..cd8dec69 100644 --- a/technical-fundamentals/coding/problems/10_LinkedList.ts +++ b/technical-fundamentals/coding/problems/10_LinkedList.ts @@ -3,29 +3,80 @@ // Create the data structure with the corresponding initial functions: export type Node = { - next?: Node | undefined; - value: T; + next?: Node | undefined; + value: T; }; export class LinkedList { - head: Node | undefined; - tail: Node | undefined; + head: Node | undefined; + tail: Node | undefined; - constructor(head?: Node) {} + constructor(head?: Node) { + this.head = head; + this.tail = head; + } - push(value: T) {} - filter() {} - visit() {} - remove() {} - merge() {} - print() {} + push(value: T) { + let newNode: Node = {value: value}; + if (this.tail) { + this.tail.next = newNode; + this.tail = newNode; + } else { + this.head = newNode; + this.tail = this.head; + } + } - // extra + filter(fn: (node: Node) => boolean): LinkedList { + const result = new LinkedList(); + if (!this.head) return this; + let p: Node | undefined = this.head; + while (p) { + if (fn(p)) { + result.push(p.value); + } + p = p.next; + } - //find(): Node {} - //get(index: number): Node {} - //iterator(): LinkedListIterator {} - length: number; + return result; + } + + visit(fn: (node: Node, index: number) => void) { + let index = 0; + let p = this.head; + while(p){ + fn(p, index); + index++; + p = p.next; + } + } + + remove() { + } + + merge(list: LinkedList): LinkedList { + if(!this.tail) return list; + this.tail.next = list.head; + this.tail = list.tail; + return this; + } + + print() { + } + + // extra + + //find(): Node {} + //get(index: number): Node {} + //iterator(): LinkedListIterator {} + + length(): number { + let length = 0; + this.visit(() => { + length++; + }); + return length; + } } const list = new LinkedList(); diff --git a/technical-fundamentals/coding/problems/11_removeDups.ts b/technical-fundamentals/coding/problems/11_removeDups.ts index 822defc6..36c7a20c 100644 --- a/technical-fundamentals/coding/problems/11_removeDups.ts +++ b/technical-fundamentals/coding/problems/11_removeDups.ts @@ -5,11 +5,56 @@ // // 1 -> 2 -> 2-> 2 -> 4 -import { LinkedList } from "./10_LinkedList"; +import {LinkedList} from "./10_LinkedList"; export type Node = { - value: T; - next?: Node; + value: T; + next?: Node; }; -export default function removeDups(head?: Node): Node | undefined {} +export default function removeDups(head?: Node): Node | undefined { + // no extra structures, just pointers + // from beginning to current position -> no dups + // each one iterates from start and if it's repeated -> jump + + let p = head; + outerWhile: while(p){ + let q = head; //q: from start to current + while(q && (q !== p)){ + if(p.next && q.value === p.next.value){ + p.next = p.next.next; + continue outerWhile; + } + q = q.next; + } + + //initial case or repetition + if(q === p && p.next && q.value === p.next.value){ + p.next = p.next.next; + continue; + } + + p = p.next; + } + + return head; + +} + +export function removeDups2(head?: Node): Node | undefined { + + const lList: LinkedList = new LinkedList(head); + const mySet: Set = new Set(); + + const ret: LinkedList = lList.filter((node: Node) => { + if (mySet.has(node.value)) { + return false; + } else { + mySet.add(node.value); + return true; + } + }); + + return ret.head; + +} diff --git a/technical-fundamentals/coding/problems/12_kthToLast.ts b/technical-fundamentals/coding/problems/12_kthToLast.ts index 460e6528..de42fc61 100644 --- a/technical-fundamentals/coding/problems/12_kthToLast.ts +++ b/technical-fundamentals/coding/problems/12_kthToLast.ts @@ -8,8 +8,33 @@ export type Node = { value: T; next?: Node; }; - export default function kthToLast( - head: Node, + head: Node | undefined, + k: number, +): Node | undefined { + let lList: LinkedList = new LinkedList(head); + const length = lList.length(); + let ret; + lList.visit((node, index) => { + if(index === length - k){ + ret = node; + } + }); + return ret; +} + +//this is O(n) but uses an array as helper +export function kthToLast2( + head: Node | undefined, k: number, -): Node | undefined {} +): Node | undefined { + const array = []; + let p = head; + let counter = 0; + while(p){ + array[counter] = p; + counter++; + p = p.next; + } + return array[counter-k]; +} diff --git a/technical-fundamentals/coding/problems/13_deleteMiddleNode.ts b/technical-fundamentals/coding/problems/13_deleteMiddleNode.ts index b9bb4464..d1d4e7c5 100644 --- a/technical-fundamentals/coding/problems/13_deleteMiddleNode.ts +++ b/technical-fundamentals/coding/problems/13_deleteMiddleNode.ts @@ -20,4 +20,39 @@ export type Node = { export default function deleteMiddleNode( head: Node, position: number, -): Node | undefined {} +): Node | undefined { + + if(position < 0) return head; + + const lList = new LinkedList(head); + lList.visit((node, index) => { + if(index === position - 1 && node.next && node.next.next){ + node.next = node.next.next; + return lList.head; + } + return null; + }); + return head; +} + +export function deleteMiddleNode2( + head: Node, + position: number, +): Node | undefined { + + let p: Node | undefined = head; + let index = 0; + if(position < 0) return head; + + while(p){ + if(index === position-1 && p.next && p.next.next) { + p.next = p.next.next; + return head; + } + index++; + p = p.next; + } + + return head; + +} diff --git a/technical-fundamentals/coding/problems/14_partition.ts b/technical-fundamentals/coding/problems/14_partition.ts index f680ab7e..ec9dc0ad 100644 --- a/technical-fundamentals/coding/problems/14_partition.ts +++ b/technical-fundamentals/coding/problems/14_partition.ts @@ -18,8 +18,58 @@ export type Node = { value: T; next?: Node; }; - export default function partition( head: Node | undefined, x: T, -): Node | undefined {} +): Node | undefined { + + const lList = new LinkedList(head); + const front = lList.filter((n) => { + return n.value < x; + }); + const back = lList.filter((n) => { + return n.value >= x; + }); + + return front.merge(back).head; +} + +//I made this without filter() and merge() +export function partition2( + head: Node | undefined, + x: T, +): Node | undefined { + + if(!head) return head; + + let p = head; + let auxList: Node = {value: {} as T}; + const auxHead = auxList; + let firstHead: Node | undefined = head; + + while(firstHead && firstHead.value < x){ + auxList.next = firstHead; + auxList = auxList.next; + firstHead = firstHead.next; + } + + const lList = new LinkedList(firstHead); + + lList.visit((n) => { + if(n.next && n.next.value < x) { + auxList.next = n.next; + n.next = n.next.next; + auxList = auxList.next; + if(n.next && !n.next.next && n.next.value < x){ + auxList.next = n.next; + auxList = auxList.next; + n.next = undefined; + } + } + }); + + auxList.next = firstHead; + return auxHead.next; + +} + diff --git a/technical-fundamentals/coding/problems/15_sumLists.ts b/technical-fundamentals/coding/problems/15_sumLists.ts index fce352a1..cf69d06e 100644 --- a/technical-fundamentals/coding/problems/15_sumLists.ts +++ b/technical-fundamentals/coding/problems/15_sumLists.ts @@ -19,4 +19,40 @@ export type Node = { export default function sumLists( list1: Node | undefined, list2: Node | undefined, -): Node | undefined {} +): Node | undefined { + + let multiplier = 1; + let result = 0; + while(list1 || list2){ + let val1; + let val2; + if(!list1) { + val1 = 0; + } else { + val1 = list1.value; + } + if(!list2) { + val2 = 0; + } else { + val2 = list2.value; + } + + result += (val1 + val2) * multiplier; + multiplier *= 10; + + list1 = list1?.next; + list2 = list2?.next; + + } + let resultNode: Node = {value: {} as number}; + const resHead = resultNode; + while(result >= 1){ + const nextD = result % 10; + result = Math.floor(result / 10); + resultNode.next = {value: nextD}; + resultNode = resultNode.next; + } + + return resHead.next; + +} diff --git a/technical-fundamentals/coding/problems/16_sumListsForwardOrder.ts b/technical-fundamentals/coding/problems/16_sumListsForwardOrder.ts index 2f426d55..37431355 100644 --- a/technical-fundamentals/coding/problems/16_sumListsForwardOrder.ts +++ b/technical-fundamentals/coding/problems/16_sumListsForwardOrder.ts @@ -16,4 +16,25 @@ export type Node = { export default function sumListsForwardOrder( list1: Node | undefined, list2: Node | undefined, -): Node | undefined {} +): Node | undefined { + let result: number = getNumber(list1) + getNumber(list2); + if(result === 0) return undefined; + let resList: Node = {value: {} as number} + const resHead = resList; + const str = String(result); + for(let i = 0; i < str.length; i++){ + resList.next = {value: Number(str[i])} + resList = resList.next; + } + return resHead.next; +} + +function getNumber(list : Node | undefined): number{ + if(!list) return 0; + const lList = new LinkedList(list); + let str = ""; + lList.visit((n: Node) => { + str += n.value; + }); + return Number(str); +} diff --git a/technical-fundamentals/coding/problems/17_palindrome.ts b/technical-fundamentals/coding/problems/17_palindrome.ts index 863c2ff2..7f9d3a47 100644 --- a/technical-fundamentals/coding/problems/17_palindrome.ts +++ b/technical-fundamentals/coding/problems/17_palindrome.ts @@ -9,4 +9,14 @@ export type Node = { next?: Node; }; -export default function isPalindrome(head: Node | undefined): boolean {} +export default function isPalindrome(head: Node | undefined): boolean { + let str1 = ""; + let str2 = ""; + if(!head) return false; + const lList = new LinkedList(head); + lList.visit((n) => { + str1 += n.value; + str2 = n.value + str2; + }); + return str1 === str2; +} diff --git a/technical-fundamentals/coding/problems/18_intersection.ts b/technical-fundamentals/coding/problems/18_intersection.ts index e9f50487..f674cd19 100644 --- a/technical-fundamentals/coding/problems/18_intersection.ts +++ b/technical-fundamentals/coding/problems/18_intersection.ts @@ -14,4 +14,16 @@ export type Node = { export default function intersection( list1: Node | undefined, list2: Node | undefined, -): Node | undefined {} +): Node | undefined { + const set: Set> = new Set>(); + const lList1 = new LinkedList(list1); + lList1.visit((n) => { + set.add(n); + }); + let p = list2; + while(p){ + if(set.has(p)) return p; + p = p.next; + } + return undefined; +} diff --git a/technical-fundamentals/coding/problems/19_loopDetection.ts b/technical-fundamentals/coding/problems/19_loopDetection.ts index d91c0b21..748bdc24 100644 --- a/technical-fundamentals/coding/problems/19_loopDetection.ts +++ b/technical-fundamentals/coding/problems/19_loopDetection.ts @@ -24,4 +24,16 @@ export type Node = { export default function detectLoop( head: Node | undefined, -): Node | null {} +): Node | null { + const set: Set> = new Set>(); + let p = head; + while(p){ + if(set.has(p)){ + return p; + } else { + set.add(p); + } + p = p.next; + } + return null; +} diff --git a/technical-fundamentals/coding/problems/__tests__/lists/11_removeDups.test.ts b/technical-fundamentals/coding/problems/__tests__/lists/11_removeDups.test.ts index 0c574e5d..593f1458 100644 --- a/technical-fundamentals/coding/problems/__tests__/lists/11_removeDups.test.ts +++ b/technical-fundamentals/coding/problems/__tests__/lists/11_removeDups.test.ts @@ -54,4 +54,31 @@ describe("11 - removeDups", () => { const result = removeDups(node1); expect(result).toEqual(node1); }); + + test("remove duplicates with heavy interleaving", () => { + const n1 = { value: "a" } as Node; + const n2 = { value: "b" } as Node; + const n3 = { value: "a" } as Node; + const n4 = { value: "c" } as Node; + const n5 = { value: "b" } as Node; + const n6 = { value: "d" } as Node; + const n7 = { value: "c" } as Node; + const n8 = { value: "a" } as Node; + + n1.next = n2; + n2.next = n3; + n3.next = n4; + n4.next = n5; + n5.next = n6; + n6.next = n7; + n7.next = n8; + + const expected = { value: "a" } as Node; + expected.next = { value: "b" } as Node; + expected.next.next = { value: "c" } as Node; + expected.next.next.next = { value: "d" } as Node; + + const result = removeDups(n1); + expect(result).toEqual(expected); + }); }); diff --git a/technical-fundamentals/coding/problems/__tests__/strings/02_checkPermutations.test.ts b/technical-fundamentals/coding/problems/__tests__/strings/02_checkPermutations.test.ts index cfac3212..e67d246c 100644 --- a/technical-fundamentals/coding/problems/__tests__/strings/02_checkPermutations.test.ts +++ b/technical-fundamentals/coding/problems/__tests__/strings/02_checkPermutations.test.ts @@ -28,4 +28,8 @@ describe('02 - checkPermutation', () =>{ test('Returns false for long strings with different characters', () =>{ expect(checkPermutations('a'.repeat(1000),'b'.repeat(1000))).toEqual(false); }); + + test('Returns false for non-permutations with subgroup in the second one -it prevents uncomplete solutions-', () =>{ + expect(checkPermutations('abc','bc')).toEqual(false); + }); }) diff --git a/technical-fundamentals/coding/problems/__tests__/strings/03_URLify.test.ts b/technical-fundamentals/coding/problems/__tests__/strings/03_URLify.test.ts index 5ec8a26d..ba9cc834 100644 --- a/technical-fundamentals/coding/problems/__tests__/strings/03_URLify.test.ts +++ b/technical-fundamentals/coding/problems/__tests__/strings/03_URLify.test.ts @@ -2,11 +2,11 @@ import URLify from "../../03_urlify"; describe('03 - URLify', () =>{ test("Replaces spaces in a string with '%20'", () =>{ - expect(URLify('ab c')).toEqual('ab%20c'); + expect(URLify([...'ab c '])).toEqual([...'ab%20c']); }); test("Handles leading and trailing spaces", () =>{ - expect(URLify(' ab c ')).toEqual('%20%20ab%20c%20%20'); + expect(URLify([...' ab c '])).toEqual([...'%20%20ab%20c']); }); test("Returns empty string when input is empty", () =>{ @@ -14,18 +14,18 @@ describe('03 - URLify', () =>{ }); test("Doesn't modify string without spaces", () =>{ - expect(URLify('abc')).toEqual('abc'); + expect(URLify([...'abc'])).toEqual([...'abc']); }); test("Handles multiple consecutive spaces", () =>{ - expect(URLify('a b c')).toEqual('a%20%20b%20%20%20c'); + expect(URLify([...'a b c '])).toEqual([...'a%20%20b%20%20%20c']); }); test("Handles special characters", () =>{ - expect(URLify('a b!c')).toEqual('a%20b!c'); + expect(URLify([...'a b!c '])).toEqual([...'a%20b!c']); }); test("Mr 3ohn Smith", () =>{ - expect(URLify('Mr 3ohn Smith')).toEqual('Mr%203ohn%20Smith'); + expect(URLify([...'Mr 3ohn Smith '])).toEqual([...'Mr%203ohn%20Smith']); }); });