From 8cb3bca0738b89dc55d2ca1f44894ebc6cf2db44 Mon Sep 17 00:00:00 2001 From: Maddy <74828969+pursuitMaddy@users.noreply.github.com> Date: Sun, 17 Jan 2021 17:59:40 -0500 Subject: [PATCH 01/12] finish --- package-lock.json | 2 +- problems/countNumbers.js | 18 ++++++++++-- problems/getCountriesSortedByPopulation.js | 11 ++++++- problems/isOdd.js | 7 +++-- problems/numberOfDigits.js | 23 +++++++++++++-- problems/removeEvenStrings.js | 34 ++++++++++++++++++++-- problems/removeNumbersAtOddIndices.js | 8 ++++- problems/removeOddNumbers.js | 5 ++-- problems/removeVowels.js | 10 ++++++- problems/secondSmallest.js | 18 ++++++++++-- problems/sevenBoom.js | 7 ++++- 11 files changed, 126 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index f383978..d73b101 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "pursuit-core-unit-one-final-assessment", + "name": "module-one-final-assessment", "version": "1.0.0", "lockfileVersion": 1, "requires": true, diff --git a/problems/countNumbers.js b/problems/countNumbers.js index 5fcc4b5..8f9e853 100644 --- a/problems/countNumbers.js +++ b/problems/countNumbers.js @@ -9,9 +9,23 @@ * returns { 1:3, 2:2, 3:1, 4:1 } */ -function countNumbers() { - +function countNumbers(arr) { + let count = {} + for (let i = 0; i < arr.length; i++) { + const el = arr[i]; + if (count[el]) { + count[el] += 1 + } else { + count[el] = 1; + + } + console.log(count) + } + + return count; + } + module.exports = countNumbers \ No newline at end of file diff --git a/problems/getCountriesSortedByPopulation.js b/problems/getCountriesSortedByPopulation.js index a5a5e58..e7adbce 100644 --- a/problems/getCountriesSortedByPopulation.js +++ b/problems/getCountriesSortedByPopulation.js @@ -7,8 +7,17 @@ * */ -function getCountriesSortedByPopulation() { +function getCountriesSortedByPopulation(arr) { + return arr.sort((country1, country2) => { + console.log(arr); + if (country2.population > country1.population) { + console.log(arr) + } + return Math.floor(country2.population - country1.population) + }) + } + module.exports = getCountriesSortedByPopulation diff --git a/problems/isOdd.js b/problems/isOdd.js index 3f7d20d..b47e16f 100644 --- a/problems/isOdd.js +++ b/problems/isOdd.js @@ -7,8 +7,11 @@ */ -function isOdd() { - +function isOdd(n) { + if (n % 2 === 1) { + return true + } + return false } module.exports = isOdd diff --git a/problems/numberOfDigits.js b/problems/numberOfDigits.js index a90ca53..97dc8ff 100644 --- a/problems/numberOfDigits.js +++ b/problems/numberOfDigits.js @@ -7,8 +7,27 @@ */ -function numberOfDigits() { - +function numberOfDigits(n) { + let num = n + return Math.floor(num.toString().length) } +// let count = 0; +// for (let i = 0; i < n; i++) { +// const count = n; +// console.log(typeof count + "first") +// if (typeof el === number ) { +// count += 1; +// console.log(typeof el + "second") +// } else { +// count = 1; +// console.log(count + "third") +// } +// console.log(count[el]) +// return count; +// } + + + + module.exports = numberOfDigits diff --git a/problems/removeEvenStrings.js b/problems/removeEvenStrings.js index fc351ae..a16d039 100644 --- a/problems/removeEvenStrings.js +++ b/problems/removeEvenStrings.js @@ -6,8 +6,38 @@ * @returns {string[]} - Returns the strings in arr that have an odd number of characters */ -function removeEvenStrings() { - +function removeEvenStrings(arr) { + console.log(arr) + let evenString = arr.filter((el) => { + console.log(el) + el % 2 === 0; + el++ + }) + return evenString } +// output = 1 +// const onlyOdds = arr.filter(el => el % 2 === 1) +// if (onlyOdds.length === 0) { +// return arr; + +// } +// for (let arr of onlyOdds) { +// console.log(arr) +// console.log(output) +// output *= arr + +// } +// return output; +// } +// let output = arr.every((string) => { +// return string % 2 === 0 +// }) +// if (output === arr) +// arr.forEach((string) => { +// if (string % 2 === 1) { +// output *= string +// } +// console.log(output + "maddy") + module.exports = removeEvenStrings diff --git a/problems/removeNumbersAtOddIndices.js b/problems/removeNumbersAtOddIndices.js index a87db28..08a17a7 100644 --- a/problems/removeNumbersAtOddIndices.js +++ b/problems/removeNumbersAtOddIndices.js @@ -2,7 +2,13 @@ * @param {number[]} arr - The input array * @returns {number[]} - An array removing all elements initially appearing at an odd index */ -function removeNumbersAtOddIndices() { +function removeNumbersAtOddIndices(arr) { + let output = arr.toString(""); + for (i = 0; i < arr.length; i += 2) + output += arr[i]; + + + return output; } diff --git a/problems/removeOddNumbers.js b/problems/removeOddNumbers.js index d7f8ae4..0a583a8 100644 --- a/problems/removeOddNumbers.js +++ b/problems/removeOddNumbers.js @@ -2,8 +2,9 @@ * @param {number[]} arr - The input array * @returns {number[]} - The input array with all odd number removed */ -function removeOddNumbers() { - +function removeOddNumbers(arr) { + let oddNumbers = arr.filter(a => a % 2 === 0) + return oddNumbers } module.exports = removeOddNumbers \ No newline at end of file diff --git a/problems/removeVowels.js b/problems/removeVowels.js index eabfd52..dd731f5 100644 --- a/problems/removeVowels.js +++ b/problems/removeVowels.js @@ -6,8 +6,16 @@ * @returns {string} - Returns a new string without any vowels. */ -function removeVowels() { +function removeVowels(str) { + let arr = str.split("") + let out = []; + for (let i = 0; i < arr.length; i++) { + if (arr[i] !== "o" && arr[i] !== "e" && arr[i] !== "u" && arr[i] !== "i" && arr[i] !== "A" && arr[i] !== "E" && arr[i] !== "I" && arr[i] !== "U" && arr[i] !== "O" && arr[i] !== "a") { + out.push(arr[i]) + } + } + return out.join("") } module.exports = removeVowels diff --git a/problems/secondSmallest.js b/problems/secondSmallest.js index 9d1ece6..6072c63 100644 --- a/problems/secondSmallest.js +++ b/problems/secondSmallest.js @@ -6,8 +6,22 @@ * @returns {number} - Returns the second smallest number. */ -function secondSmallest() { - +function secondSmallest(arr) { + let arr1 = 99; + let arr2 = 99; + + for (let i = 0; i < arr.length; i++) { + const num = arr[i] + if (num < arr1) { + arr2 = arr1 + arr1 = num + } else if (num < arr2) { + arr2 = num + + } + } + return arr2 + } module.exports = secondSmallest diff --git a/problems/sevenBoom.js b/problems/sevenBoom.js index 14b2a07..c21aa09 100644 --- a/problems/sevenBoom.js +++ b/problems/sevenBoom.js @@ -4,7 +4,12 @@ * @param {number} n - The number to count up to * @returns {number[]} - An array matching the pattern described above */ -function sevenBoom() { +function sevenBoom(num) { + + let output = num.every((el) => { + Math.floor(el * 7) && (el % 10 === 7).replace("BOOM") + return output + }) } From 96bf01441c63ae49646dffb03eb1fda80b7478c7 Mon Sep 17 00:00:00 2001 From: Maddy <74828969+pursuitMaddy@users.noreply.github.com> Date: Wed, 20 Jan 2021 22:02:15 -0500 Subject: [PATCH 02/12] claas review --- problems/getCountriesSortedByPopulation.js | 20 ++++++++---- problems/removeEvenStrings.js | 37 +++------------------- problems/removeNumbersAtOddIndices.js | 9 ++++-- problems/secondSmallest.js | 9 ++++++ problems/sevenBoom.js | 22 +++++++++---- 5 files changed, 48 insertions(+), 49 deletions(-) diff --git a/problems/getCountriesSortedByPopulation.js b/problems/getCountriesSortedByPopulation.js index e7adbce..5fad197 100644 --- a/problems/getCountriesSortedByPopulation.js +++ b/problems/getCountriesSortedByPopulation.js @@ -7,17 +7,23 @@ * */ -function getCountriesSortedByPopulation(arr) { - return arr.sort((country1, country2) => { - console.log(arr); - if (country2.population > country1.population) { - console.log(arr) - } - return Math.floor(country2.population - country1.population) +function getCountriesSortedByPopulation(countries) { + countries.sort((country1, country2) => { + + return country2.population - country1.population; + }) + return countries.map((country) => { + + return country.country; + + + }) } + + module.exports = getCountriesSortedByPopulation diff --git a/problems/removeEvenStrings.js b/problems/removeEvenStrings.js index a16d039..9b924fc 100644 --- a/problems/removeEvenStrings.js +++ b/problems/removeEvenStrings.js @@ -6,38 +6,11 @@ * @returns {string[]} - Returns the strings in arr that have an odd number of characters */ -function removeEvenStrings(arr) { - console.log(arr) - let evenString = arr.filter((el) => { - console.log(el) - el % 2 === 0; - el++ - }) - return evenString -} -// output = 1 -// const onlyOdds = arr.filter(el => el % 2 === 1) -// if (onlyOdds.length === 0) { -// return arr; - -// } -// for (let arr of onlyOdds) { -// console.log(arr) -// console.log(output) -// output *= arr - -// } -// return output; -// } -// let output = arr.every((string) => { -// return string % 2 === 0 -// }) -// if (output === arr) -// arr.forEach((string) => { -// if (string % 2 === 1) { -// output *= string -// } -// console.log(output + "maddy") +function removeEvenStrings(words) { + return words.filter((word) => { + return word.length % 2 === 1 + }); +} module.exports = removeEvenStrings diff --git a/problems/removeNumbersAtOddIndices.js b/problems/removeNumbersAtOddIndices.js index 08a17a7..418822c 100644 --- a/problems/removeNumbersAtOddIndices.js +++ b/problems/removeNumbersAtOddIndices.js @@ -3,9 +3,12 @@ * @returns {number[]} - An array removing all elements initially appearing at an odd index */ function removeNumbersAtOddIndices(arr) { - let output = arr.toString(""); - for (i = 0; i < arr.length; i += 2) - output += arr[i]; + let output = []; + for (i = 0; i < arr.length; i += 2) { + output.push(arr[i]); + + } + return output; diff --git a/problems/secondSmallest.js b/problems/secondSmallest.js index 6072c63..68f187d 100644 --- a/problems/secondSmallest.js +++ b/problems/secondSmallest.js @@ -7,6 +7,15 @@ */ function secondSmallest(arr) { + + + if (arr.length < 2) { + return null; + } + arr.sort((a, b) => a - b) + return arr[1]; + + let arr1 = 99; let arr2 = 99; diff --git a/problems/sevenBoom.js b/problems/sevenBoom.js index c21aa09..c5fe394 100644 --- a/problems/sevenBoom.js +++ b/problems/sevenBoom.js @@ -4,13 +4,21 @@ * @param {number} n - The number to count up to * @returns {number[]} - An array matching the pattern described above */ -function sevenBoom(num) { - - let output = num.every((el) => { - Math.floor(el * 7) && (el % 10 === 7).replace("BOOM") - return output - }) - +function sevenBoom(n) { + const output = []; + for (let i = 1; i <= n; i++) { + if (i % 7 === 0 || i.toString().includes("7")) { + output.push('BOOM') + } else { + output.push(i) + } + } + return output } +// let output = num.every((el) => { +// Math.floor(el * 7) && (el % 10 === 7).replace("BOOM") +// return output +// }) + module.exports = sevenBoom \ No newline at end of file From 55ced42fecfa4f5c1be75029741aa61192a77d48 Mon Sep 17 00:00:00 2001 From: Maddy <74828969+pursuitMaddy@users.noreply.github.com> Date: Sat, 23 Jan 2021 10:15:40 -0500 Subject: [PATCH 03/12] revised --- problems/secondSmallest.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/problems/secondSmallest.js b/problems/secondSmallest.js index 68f187d..22e5711 100644 --- a/problems/secondSmallest.js +++ b/problems/secondSmallest.js @@ -9,15 +9,15 @@ function secondSmallest(arr) { - if (arr.length < 2) { - return null; - } - arr.sort((a, b) => a - b) - return arr[1]; + // if (arr.length < 2) { + // return null; + // } + // arr.sort((a, b) => a - b) + // return arr[1]; - let arr1 = 99; - let arr2 = 99; + let arr1 = Infinity; + let arr2 = Infinity; for (let i = 0; i < arr.length; i++) { const num = arr[i] From edf414307adf84c1b612701026d9d28382c0493b Mon Sep 17 00:00:00 2001 From: Maddy <74828969+pursuitMaddy@users.noreply.github.com> Date: Sat, 23 Jan 2021 15:15:22 -0500 Subject: [PATCH 04/12] revised --- problems/sevenBoom.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/problems/sevenBoom.js b/problems/sevenBoom.js index c5fe394..f3843f8 100644 --- a/problems/sevenBoom.js +++ b/problems/sevenBoom.js @@ -8,12 +8,12 @@ function sevenBoom(n) { const output = []; for (let i = 1; i <= n; i++) { if (i % 7 === 0 || i.toString().includes("7")) { - output.push('BOOM') + output.push('BOOM'); } else { - output.push(i) + output.push(i); } } - return output + return output; } // let output = num.every((el) => { // Math.floor(el * 7) && (el % 10 === 7).replace("BOOM") From ffed09465d633e605a43180289f5f3b7ef471621 Mon Sep 17 00:00:00 2001 From: Maddy <74828969+pursuitMaddy@users.noreply.github.com> Date: Sat, 23 Jan 2021 15:22:31 -0500 Subject: [PATCH 05/12] revised --- problems/secondSmallest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/secondSmallest.js b/problems/secondSmallest.js index 22e5711..d6bece8 100644 --- a/problems/secondSmallest.js +++ b/problems/secondSmallest.js @@ -29,7 +29,7 @@ function secondSmallest(arr) { } } - return arr2 + return arr2; } From 0565d7e2df8fe0d3786d1b9de38a5fd5b8d8675d Mon Sep 17 00:00:00 2001 From: Maddy <74828969+pursuitMaddy@users.noreply.github.com> Date: Mon, 25 Jan 2021 16:58:25 -0500 Subject: [PATCH 06/12] fixed naming --- problems/secondSmallest.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/problems/secondSmallest.js b/problems/secondSmallest.js index d6bece8..b40cdff 100644 --- a/problems/secondSmallest.js +++ b/problems/secondSmallest.js @@ -16,20 +16,20 @@ function secondSmallest(arr) { // return arr[1]; - let arr1 = Infinity; - let arr2 = Infinity; + let smallest = Infinity; + let secondSmallest = Infinity; for (let i = 0; i < arr.length; i++) { const num = arr[i] - if (num < arr1) { - arr2 = arr1 - arr1 = num - } else if (num < arr2) { - arr2 = num + if (num < smallest) { + secondSmallest = smallest + smallest = num + } else if (num < secondSmallest) { + secondSmallest = num } } - return arr2; + return secondSmallest; } From cb64acad8c7af9aa2d15766a9341461930e61469 Mon Sep 17 00:00:00 2001 From: Maddy <74828969+pursuitMaddy@users.noreply.github.com> Date: Wed, 27 Jan 2021 15:22:27 -0500 Subject: [PATCH 07/12] reviewing with Peter --- problems/removeEvenStrings.js | 17 +++++++++++++---- problems/removeOddNumbers.js | 11 +++++++++-- problems/sevenBoom.js | 12 +++++------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/problems/removeEvenStrings.js b/problems/removeEvenStrings.js index 9b924fc..b471445 100644 --- a/problems/removeEvenStrings.js +++ b/problems/removeEvenStrings.js @@ -6,11 +6,20 @@ * @returns {string[]} - Returns the strings in arr that have an odd number of characters */ -function removeEvenStrings(words) { - return words.filter((word) => { - return word.length % 2 === 1 - }); +function removeEvenStrings(arr) { + let ouptut = []; + for (let i = 0; i < arr.length; i++) { + if (arr[i].length % 2 === 1) { + ouptut.push(arr[i]); + } + } + return ouptut; } module.exports = removeEvenStrings + + +//Write down the steps to solve the question +//Use a sample input +//Sample output diff --git a/problems/removeOddNumbers.js b/problems/removeOddNumbers.js index 0a583a8..be743c5 100644 --- a/problems/removeOddNumbers.js +++ b/problems/removeOddNumbers.js @@ -3,8 +3,15 @@ * @returns {number[]} - The input array with all odd number removed */ function removeOddNumbers(arr) { - let oddNumbers = arr.filter(a => a % 2 === 0) - return oddNumbers + let output = []; + for (let i = 0; i < arr.length; i++) { + if (arr[i] % 2 === 0) { + output.push(arr[i]); + } + } + return output; } + + module.exports = removeOddNumbers \ No newline at end of file diff --git a/problems/sevenBoom.js b/problems/sevenBoom.js index f3843f8..c9107c2 100644 --- a/problems/sevenBoom.js +++ b/problems/sevenBoom.js @@ -5,20 +5,18 @@ * @returns {number[]} - An array matching the pattern described above */ function sevenBoom(n) { - const output = []; + let output = []; for (let i = 1; i <= n; i++) { if (i % 7 === 0 || i.toString().includes("7")) { - output.push('BOOM'); + output.push("BOOM") } else { - output.push(i); + output.push(i) } + console.log(output); } return output; } -// let output = num.every((el) => { -// Math.floor(el * 7) && (el % 10 === 7).replace("BOOM") -// return output -// }) + module.exports = sevenBoom \ No newline at end of file From b334d9d04787a008ba17ed8dad7d00978c8276e5 Mon Sep 17 00:00:00 2001 From: Maddy <74828969+pursuitMaddy@users.noreply.github.com> Date: Fri, 29 Jan 2021 15:54:36 -0500 Subject: [PATCH 08/12] updted countNumber to forEach method. --- problems/countNumbers.js | 37 ++++++++++++++++++++++++++----------- problems/numberOfDigits.js | 16 ---------------- problems/sevenBoom.js | 1 - 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/problems/countNumbers.js b/problems/countNumbers.js index 8f9e853..a95d643 100644 --- a/problems/countNumbers.js +++ b/problems/countNumbers.js @@ -10,21 +10,36 @@ */ function countNumbers(arr) { - let count = {} - for (let i = 0; i < arr.length; i++) { - const el = arr[i]; - if (count[el]) { - count[el] += 1 + const output = {}; + arr.forEach(el => { + if (output[el]) { + output[el] += 1; } else { - count[el] = 1; - + output[el] = 1; } - console.log(count) - } + console.log(output) + }) + return output +} - return count; -} + + + +// let count = {} +// for (let i = 0; i < arr.length; i++) { +// const el = arr[i]; +// if (count[el]) { +// count[el] += 1 +// } else { +// count[el] = 1; + +// } +// } + +// return count; + +// } diff --git a/problems/numberOfDigits.js b/problems/numberOfDigits.js index 97dc8ff..0186c02 100644 --- a/problems/numberOfDigits.js +++ b/problems/numberOfDigits.js @@ -12,22 +12,6 @@ function numberOfDigits(n) { return Math.floor(num.toString().length) } -// let count = 0; -// for (let i = 0; i < n; i++) { -// const count = n; -// console.log(typeof count + "first") -// if (typeof el === number ) { -// count += 1; -// console.log(typeof el + "second") -// } else { -// count = 1; -// console.log(count + "third") -// } -// console.log(count[el]) -// return count; -// } - - module.exports = numberOfDigits diff --git a/problems/sevenBoom.js b/problems/sevenBoom.js index c9107c2..20be693 100644 --- a/problems/sevenBoom.js +++ b/problems/sevenBoom.js @@ -12,7 +12,6 @@ function sevenBoom(n) { } else { output.push(i) } - console.log(output); } return output; } From 9fefb581704dc90852e068ace7af2a65e033d153 Mon Sep 17 00:00:00 2001 From: Maddy <74828969+pursuitMaddy@users.noreply.github.com> Date: Fri, 29 Jan 2021 16:00:39 -0500 Subject: [PATCH 09/12] updated is Odd to return one line --- problems/isOdd.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/problems/isOdd.js b/problems/isOdd.js index b47e16f..e4c1da9 100644 --- a/problems/isOdd.js +++ b/problems/isOdd.js @@ -8,10 +8,7 @@ */ function isOdd(n) { - if (n % 2 === 1) { - return true - } - return false + return n % 2 === 1; } module.exports = isOdd From 0efa0de534d73d4467201ba59922422123ae152f Mon Sep 17 00:00:00 2001 From: Maddy <74828969+pursuitMaddy@users.noreply.github.com> Date: Fri, 29 Jan 2021 19:22:03 -0500 Subject: [PATCH 10/12] used filter on remove number --- problems/numberOfDigits.js | 2 +- problems/removeNumbersAtOddIndices.js | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/problems/numberOfDigits.js b/problems/numberOfDigits.js index 0186c02..1bef99c 100644 --- a/problems/numberOfDigits.js +++ b/problems/numberOfDigits.js @@ -9,7 +9,7 @@ function numberOfDigits(n) { let num = n - return Math.floor(num.toString().length) + return num.toString().length } diff --git a/problems/removeNumbersAtOddIndices.js b/problems/removeNumbersAtOddIndices.js index 418822c..9bcbb89 100644 --- a/problems/removeNumbersAtOddIndices.js +++ b/problems/removeNumbersAtOddIndices.js @@ -3,16 +3,20 @@ * @returns {number[]} - An array removing all elements initially appearing at an odd index */ function removeNumbersAtOddIndices(arr) { - let output = []; - for (i = 0; i < arr.length; i += 2) { - output.push(arr[i]); + let output = arr.filter((el, index) => !(index % 2)); + return output; +} - } - return output; -} + +// for (i = 0; i < arr.length; i += 2) { +// output.push(arr[i]); + +// } + + module.exports = removeNumbersAtOddIndices \ No newline at end of file From ceb047155d6495d79f366b9e9ae5a3d17abf6c09 Mon Sep 17 00:00:00 2001 From: Maddy <74828969+pursuitMaddy@users.noreply.github.com> Date: Fri, 29 Jan 2021 21:09:49 -0500 Subject: [PATCH 11/12] used filter method on OddNumber --- problems/removeEvenStrings.js | 22 ++++++++++++++-------- problems/removeNumbersAtOddIndices.js | 2 +- problems/removeOddNumbers.js | 15 +++++++++------ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/problems/removeEvenStrings.js b/problems/removeEvenStrings.js index b471445..e577b3f 100644 --- a/problems/removeEvenStrings.js +++ b/problems/removeEvenStrings.js @@ -7,16 +7,22 @@ */ function removeEvenStrings(arr) { - let ouptut = []; - for (let i = 0; i < arr.length; i++) { - if (arr[i].length % 2 === 1) { - ouptut.push(arr[i]); - } - } - - return ouptut; + output = arr.filter((el, index) => !(index % 2)); + return output; } + + + +// let ouptut = []; +// for (let i = 0; i < arr.length; i++) { +// if (arr[i].length % 2 === 1) { +// ouptut.push(arr[i]); +// } +// } + +// return ouptut; + module.exports = removeEvenStrings diff --git a/problems/removeNumbersAtOddIndices.js b/problems/removeNumbersAtOddIndices.js index 9bcbb89..e59cd22 100644 --- a/problems/removeNumbersAtOddIndices.js +++ b/problems/removeNumbersAtOddIndices.js @@ -3,7 +3,7 @@ * @returns {number[]} - An array removing all elements initially appearing at an odd index */ function removeNumbersAtOddIndices(arr) { - let output = arr.filter((el, index) => !(index % 2)); + output = arr.filter((el, index) => !(index % 2)); return output; } diff --git a/problems/removeOddNumbers.js b/problems/removeOddNumbers.js index be743c5..05a13bc 100644 --- a/problems/removeOddNumbers.js +++ b/problems/removeOddNumbers.js @@ -3,12 +3,15 @@ * @returns {number[]} - The input array with all odd number removed */ function removeOddNumbers(arr) { - let output = []; - for (let i = 0; i < arr.length; i++) { - if (arr[i] % 2 === 0) { - output.push(arr[i]); - } - } + + let output = arr.filter((el, index) => !(el % 2)); + + // let output = []; + // for (let i = 0; i < arr.length; i++) { + // if (arr[i] % 2 === 0) { + // output.push(arr[i]); + // } + // } return output; } From 23857a08da68027d5c590b0c412dc7c1ec0fe19a Mon Sep 17 00:00:00 2001 From: Maddy <74828969+pursuitMaddy@users.noreply.github.com> Date: Fri, 29 Jan 2021 21:29:00 -0500 Subject: [PATCH 12/12] using filter method on string --- problems/removeEvenStrings.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/problems/removeEvenStrings.js b/problems/removeEvenStrings.js index e577b3f..e1ffb94 100644 --- a/problems/removeEvenStrings.js +++ b/problems/removeEvenStrings.js @@ -7,13 +7,12 @@ */ function removeEvenStrings(arr) { - output = arr.filter((el, index) => !(index % 2)); + const output = arr.filter(el => el.length % 2 === 1) return output; } - // let ouptut = []; // for (let i = 0; i < arr.length; i++) { // if (arr[i].length % 2 === 1) { @@ -23,6 +22,7 @@ function removeEvenStrings(arr) { // return ouptut; + module.exports = removeEvenStrings