From 70aad4848c7cf1ab783417c7e35ed398ff4c6cda Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Fri, 8 Nov 2024 15:01:11 +0000 Subject: [PATCH 01/11] sprint3- implement- get angle type js --- Sprint-3/implement/get-angle-type.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Sprint-3/implement/get-angle-type.js b/Sprint-3/implement/get-angle-type.js index db952494..710fdd02 100644 --- a/Sprint-3/implement/get-angle-type.js +++ b/Sprint-3/implement/get-angle-type.js @@ -25,3 +25,25 @@ // Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" + + +function getAngleType(angle){ + if (angle == 90){ + return "Right angle" + } + else if(angle < 90){ + return "Acute angle" + } + else if(angle > 90 && angle < 180){ + return "Obtuse angle" + } + else if(angle == 180){ + return "Straight angle" + } + else if(angle > 180 && angle < 360){ + return "Relax angle" + } + +} + +console.log(getAngleType(250)); \ No newline at end of file From 77746f9d8b9a1530f044fa82bcbb452c20355f2d Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Sat, 9 Nov 2024 11:20:35 +0000 Subject: [PATCH 02/11] sprint3-implement-get card value js --- Sprint-3/implement/get-card-value.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Sprint-3/implement/get-card-value.js b/Sprint-3/implement/get-card-value.js index edaeb827..b5af55ea 100644 --- a/Sprint-3/implement/get-card-value.js +++ b/Sprint-3/implement/get-card-value.js @@ -29,3 +29,31 @@ // Given a card with an invalid rank (neither a number nor a recognized face card), // When the function is called with such a card, // Then it should throw an error indicating "Invalid card rank." + +function getCardValue(card){ + let num = card[0]; + if(Number(num) >= 2 && Number(num) < 10){ + return `${num}${card[1]}` + } + else if(num == "A"){ + return `11${card[1]}` + } + else if (num == 10 || num == "J" || num == "Q" || num == "K"){ + return `10${card[1]}` + } + + +} + +let currentOutput = getCardValue("5♠"); +let targetOutput = "5♠"; +console.assert( + currentOutput === targetOutput, + `current output: ${currentOutput}, target output: ${targetOutput}` + ); + + +console.log(getCardValue("K♣️")); + + +// \ No newline at end of file From 7fc4ae2d2d9e46bb7a476cb41a5b604f2e1bc8c7 Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Sat, 9 Nov 2024 12:13:37 +0000 Subject: [PATCH 03/11] sprint3-implement- is proper fraction js --- Sprint-3/implement/is-proper-fraction.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Sprint-3/implement/is-proper-fraction.js b/Sprint-3/implement/is-proper-fraction.js index 6493da0b..6a79aef0 100644 --- a/Sprint-3/implement/is-proper-fraction.js +++ b/Sprint-3/implement/is-proper-fraction.js @@ -32,3 +32,27 @@ // target output: false // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. // These acceptance criteria cover a range of scenarios to ensure that the isProperFraction function handles both proper and improper fractions correctly and handles potential errors such as a zero denominator. + +function isProperFraction(numerator, denominator){ + if (numerator < 0){ + numerator = numerator * (-1); + } + if(denominator == 0){ + throw new Error("denominator should not be equal to Zero"); + } + if(numerator < denominator){ + return true + } + else if(numerator >= denominator){ + return false + } +} + +console.log(isProperFraction(3, 5)); + +let currentOutput = isProperFraction(2, 3); +let targetOutput = true; +console.assert( + currentOutput == targetOutput, + `currentOutput ${currentOutput} is not equal to targetOutput ${targetOutput}` +); \ No newline at end of file From 5946df54ab3e87e3534f07a7fafd62715b6e56b2 Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Sat, 9 Nov 2024 12:32:07 +0000 Subject: [PATCH 04/11] sprint3-implement-is valid triangle js --- Sprint-3/implement/is-valid-triangle.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Sprint-3/implement/is-valid-triangle.js b/Sprint-3/implement/is-valid-triangle.js index f3643ab2..fa0b4d5a 100644 --- a/Sprint-3/implement/is-valid-triangle.js +++ b/Sprint-3/implement/is-valid-triangle.js @@ -33,3 +33,20 @@ // Then it should return true because the input forms a valid triangle. // This specification outlines the behavior of the isValidTriangle function for different input scenarios, ensuring it properly checks for invalid side lengths and whether they form a valid triangle according to the Triangle Inequality Theorem. + +function isValidTriangle(a, b, c){ + if(a == 0 || b == 0 || c == 0){ + return false + } + if(a + b <= c || a + c <= b || b + c <= a){ + return false + } + // else if(a + b >= c || a + c >= b || b + c >= a){ + return true + //} +} + + +console.log(isValidTriangle(1, 1, 1)); + +console.assert(isValidTriangle(23, 45, 97), "its false because sum of the 23 and 45 is greater than 67"); From 366095e3f7754044df8b6309117538528eb050a1 Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Sat, 9 Nov 2024 13:54:40 +0000 Subject: [PATCH 05/11] sprint3-implement-rotate char js --- Sprint-3/implement/rotate-char.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Sprint-3/implement/rotate-char.js b/Sprint-3/implement/rotate-char.js index e8c96131..97a867a9 100644 --- a/Sprint-3/implement/rotate-char.js +++ b/Sprint-3/implement/rotate-char.js @@ -16,6 +16,34 @@ // Given a lowercase letter character and a positive integer shift, // When the function is called with these inputs, // Then it should rotate the lowercase letter by shift positions within the lowercase alphabet, wrapping around if necessary, and return the rotated lowercase letter as a string. +let ALPHABET = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "U", "V", "w", "x", "y", "z"]; +let ALPHABET_UPPERCASE = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]; + +function rotateCharacter(char , num){ + + let result = ""; + for(let i = 0; i < ALPHABET.length; i++){ + if(char == ALPHABET[i]){ + if(i+num >=26){ + let a = (i+num) % 26; + return ALPHABET[a]; + } + result = ALPHABET[i + num] + + return result + } + if(char == ALPHABET_UPPERCASE[i]){ + if(i+num >=26){ + let a = (i+num) % 26; + return ALPHABET_UPPERCASE[a]; + } + result = ALPHABET_UPPERCASE[i + num] + + return result + } + } + return char; +} console.log(rotateCharacter("a", 3)); // Output: "d" console.log(rotateCharacter("f", 1)); // Output: "g" @@ -23,6 +51,7 @@ console.log(rotateCharacter("f", 1)); // Output: "g" // Given an uppercase letter character and a positive integer shift, // When the function is called with these inputs, // Then it should rotate the uppercase letter by shift positions within the uppercase alphabet, wrapping around if necessary, and return the rotated uppercase letter as a string. + console.log(rotateCharacter("A", 3)); // Output: "D" console.log(rotateCharacter("F", 1)); // Output: "G" From 1c2b2f34a11a82accc0f87a6a3444274ba2689c6 Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Sat, 9 Nov 2024 15:24:00 +0000 Subject: [PATCH 06/11] sprint3-revise-implement-card validator js --- Sprint-3/revise/implement/card-validator.js | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Sprint-3/revise/implement/card-validator.js diff --git a/Sprint-3/revise/implement/card-validator.js b/Sprint-3/revise/implement/card-validator.js new file mode 100644 index 00000000..d573e18e --- /dev/null +++ b/Sprint-3/revise/implement/card-validator.js @@ -0,0 +1,38 @@ +function card_validator(number){ + let num = []; + // we'll get the number and put it in a list + while(number != 0){ + num.push(number % 10); + number = Math.floor(number / 10); + } + num.reverse(); + let freqMap = { + 0:0,1:0,2:0,3:0 + }; + let sum = 0; + num.forEach(x => { + freqMap[x]=( (freqMap[x]) ? freqMap[x] : 0) + 1; + sum += x; + }) + console.log(freqMap) + let noneZeros = 0; + Object.keys(freqMap).forEach(x=>{ + if(freqMap[x] > 0){ + noneZeros++; + } + }) + console.log(noneZeros) + if(noneZeros >= 2 && (num[15] % 2) == 0 && sum > 16){ // checking the condintions two diffirent digits, last digit must be even and sum must be greater than 16 + return true; + + } + else{ + return false; + } + // console.log(noneZeros) +} + +console.log(card_validator(1111222233334444)); +console.log(card_validator(4444444444444444)); +console.log(card_validator(1111111111111110)); + From 19d79bad216c8252e0bf812c54aa885b8ee70990 Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Sat, 9 Nov 2024 15:41:14 +0000 Subject: [PATCH 07/11] sprint3-revise-implement-count test js --- Sprint-3/revise/implement/count.test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Sprint-3/revise/implement/count.test.js b/Sprint-3/revise/implement/count.test.js index d85877b0..a5016900 100644 --- a/Sprint-3/revise/implement/count.test.js +++ b/Sprint-3/revise/implement/count.test.js @@ -15,3 +15,25 @@ // And a character char that does not exist within the case-sensitive str, // When the function is called with these inputs, // Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str. + +function countChar(str, char){ + let str_list = []; + for(let i = 0;i < str.length; i++){ + str_list.push(str[i]); + } + console.log(str_list); + let sum = 0; + for(let j=0; j < str_list.length; j++){ + if(char == str_list[j]){ + sum++ + } + } + if(sum > 0){ + return sum + } + else{ + return 0 + } +} + +console.log(countChar("asldajaa", "z")); From 5825d6a8c87f8961cd71ed2744b8a754d5cb3cb0 Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Sat, 9 Nov 2024 16:05:34 +0000 Subject: [PATCH 08/11] sprint3-revise-implement-is prime test js --- Sprint-3/revise/implement/is-prime.test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-3/revise/implement/is-prime.test.js b/Sprint-3/revise/implement/is-prime.test.js index 382ce74f..dde2430e 100644 --- a/Sprint-3/revise/implement/is-prime.test.js +++ b/Sprint-3/revise/implement/is-prime.test.js @@ -1,3 +1,16 @@ // Given a positive integer num, // When the isPrime function is called with num as input, // Then it should check if the num is prime + +function isPrime(num){ + if (num <= 1) return false; + else if (num <= 3) return true; + else if(num % 2 == 0 || num % 3 == 0){ + return false; + } + else if (num % 1 == 0 && num % num == 0){ + return true + } +} + +console.log(isPrime(277473)); \ No newline at end of file From a40495a7d6e4ca78d2cb4a0460fdfe3f012b28f9 Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Sun, 10 Nov 2024 22:29:13 +0000 Subject: [PATCH 09/11] sprint3-revise-implement- password validator test js --- .../implement/password-validator.test.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Sprint-3/revise/implement/password-validator.test.js b/Sprint-3/revise/implement/password-validator.test.js index dfc7cedb..3c76219e 100644 --- a/Sprint-3/revise/implement/password-validator.test.js +++ b/Sprint-3/revise/implement/password-validator.test.js @@ -14,3 +14,26 @@ To be valid, a password must: You must breakdown this problem in order to solve it. Find one test case first and get that working */ +function passValidation(newPassword, previousPasswords){ + if (newPassword.length < 5){ + return false; + } + let hasUpperCase = /[A-Z]/.test(newPassword); + let hasLowerCase = /[a-z]/.test(newPassword); + let hasNumber = /[0-9]/.test(newPassword); + let hasNonAlpha = /["!""#""$""%"".""*""&"]/.test(newPassword); + + if(!hasUpperCase || !hasLowerCase || !hasNumber || !hasNonAlpha){ + return false; + } + if(previousPasswords.includes(newPassword)){ + return false; + } + return true +} + + +let PASSWORDS = ["Liver12345!", "London12345?", "Sheff12345!?"]; +console.log(passValidation("Liver12345.", PASSWORDS)); + +console.assert(passValidation("England54321", PASSWORDS), "test failed. write a valid password"); \ No newline at end of file From fc98a96463fa65c9abe4e648656cfee7842a3545 Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Sun, 10 Nov 2024 22:54:25 +0000 Subject: [PATCH 10/11] sprint3-revise-implement-repeat test js --- Sprint-3/revise/implement/repeat.test.js | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Sprint-3/revise/implement/repeat.test.js b/Sprint-3/revise/implement/repeat.test.js index 0b2b0a3e..0029be70 100644 --- a/Sprint-3/revise/implement/repeat.test.js +++ b/Sprint-3/revise/implement/repeat.test.js @@ -23,3 +23,30 @@ // Given a target string str and a negative integer count, // When the repeat function is called with these inputs, // Then it should throw an error or return an appropriate error message, as negative counts are not valid. + + +function repeat(str, count){ + let text = ""; + if(count > 1 && count < 10){ + for(let i = 1; i <= count; i++){ + text += str; + } + return text; + } + if(count == 1){ + return str; + } + if(count == 0){ + return text; + } + if(count < 0){ + throw new Error("The count must not be a negative number!"); + } + + +} + +console.log(repeat("hello", 3)); + +// I set acondition that count should not be greater than 9 +console.assert(repeat("hello", 11), "test failed, in valid count number"); \ No newline at end of file From 56680fb7b24cea8c8ffd54e129f98e0eb9f7703a Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Mon, 11 Nov 2024 21:57:58 +0000 Subject: [PATCH 11/11] sprint3-revise-investigate- fins js --- Sprint-3/revise/investigate/find.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-3/revise/investigate/find.js b/Sprint-3/revise/investigate/find.js index c7e79a2f..d368dd9e 100644 --- a/Sprint-3/revise/investigate/find.js +++ b/Sprint-3/revise/investigate/find.js @@ -20,6 +20,11 @@ console.log(find("code your future", "z")); // Pay particular attention to the following: // a) How the index variable updates during the call to find +// index updates: Starts at 0 and goes up by 1 each time, checking each character in the string. // b) What is the if statement used to check +// if statement: Checks if the current character matches the one we’re looking for. If it does, it returns the position. // c) Why is index++ being used? +// index++: Moves to the next character so we don’t get stuck on the same one. // d) What is the condition index < str.length used for? +// index < str.length: Makes sure we stop when we reach the end of the string. +