From ca1c9d3b1a75832b74e6063178e84c8477a040e2 Mon Sep 17 00:00:00 2001 From: WholesomeAhki Date: Tue, 11 Oct 2022 18:23:28 -0400 Subject: [PATCH 1/3] innitial commit --- arraySolution.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 arraySolution.js diff --git a/arraySolution.js b/arraySolution.js new file mode 100644 index 0000000..68f255d --- /dev/null +++ b/arraySolution.js @@ -0,0 +1,27 @@ +/*Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone number. + +Example +createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) // => returns "(123) 456-7890" +The returned format must be correct in order to complete this challenge. + +Don't forget the space after the closing parentheses! + + +const chai = require("chai"); +const assert = chai.assert; +chai.config.truncateThreshold=0; + +describe("Create Phone Number", () => { + it("Fixed tests", () => { + assert.strictEqual(createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]), "(123) 456-7890"); + assert.strictEqual(createPhoneNumber([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), "(111) 111-1111"); + assert.strictEqual(createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]), "(123) 456-7890"); + }); +}); */ + + +function createPhoneNumber(numbers){ + + return `(${numbers[0]}${numbers[1]}${numbers[2]}) ${numbers[3]}${numbers[4]}${numbers[5]}-${numbers[6]}${numbers[7]}${numbers[8]}${numbers[9]}` + } + \ No newline at end of file From ca3c86c929d6fd249b54ba4327b2ee96f128be80 Mon Sep 17 00:00:00 2001 From: WholesomeAhki Date: Mon, 17 Oct 2022 22:32:13 -0400 Subject: [PATCH 2/3] while loop solution --- whileLoopSolution.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 whileLoopSolution.js diff --git a/whileLoopSolution.js b/whileLoopSolution.js new file mode 100644 index 0000000..5307b15 --- /dev/null +++ b/whileLoopSolution.js @@ -0,0 +1,28 @@ +//loop solution for Task +/*Complete function padIt, which accepts 2 parameters: + +str: a string representing the string to pad. We will pad it with "*" symbols on its left side and on its right side. +n: a number indicating how many times to pad the string. +Behaviour +You need to write a loop statement within the function that loops n times. Each time through the loop it will add one * to str, alternating on which side it is padded: the first time will add a * to the left side of str, the second time will add a * to the right side, and so on. + +Finally, return the padded string.*/ + + + +function padIt(str,n){ + //declaring function passing in parameters + while(n>0){ + //while statement that "while" variable "n" is more than 0 function will run// + if(n%2 === 0) { + str = str + "*"; + //if "n" is divisible by 2 and equals 0 string gets a "*" added to the right + }else{ + str = "*" + str; + }//else string add to left + n --; + //confused about this one + } + return str; + //return string to orginal postion (able to be ran again) + } \ No newline at end of file From 478ab304dd008e6331578bfeab64a8bc1f33c054 Mon Sep 17 00:00:00 2001 From: WholesomeAhki Date: Tue, 18 Oct 2022 22:34:46 -0400 Subject: [PATCH 3/3] boolean loop solution --- booleanArraySolution.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 booleanArraySolution.js diff --git a/booleanArraySolution.js b/booleanArraySolution.js new file mode 100644 index 0000000..f78b925 --- /dev/null +++ b/booleanArraySolution.js @@ -0,0 +1,19 @@ +/*Consider an array/list of sheep where some sheep may be missing from their place. We need a function that counts the number of sheep present in the array (true means present). + +For example, + +[true, true, true, false, + true, true, true, true , + true, false, true, false, + true, false, false, true , + true, true, true, true , + false, false, true, true] +The correct answer would be 17. + +Hint: Don't forget to check for bad values like null/undefined*/ + +function countSheeps(arrayOfSheep) { + const present = arrayOfSheep.filter(sheep => sheep); + return present.length; + } +