-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Carina Taveras #170
Open
tCarina
wants to merge
11
commits into
joinpursuit:master
Choose a base branch
from
tCarina:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Carina Taveras #170
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
620c6e5
at findSecondSmallest
dalizcruz d4e41cb
at endsWithFiveWhileLoop
dalizcruz aee07fc
nada
tCarina 3ffd83c
Merge branch 'master' of github.com:dalizcruz/Pursuit-Core-Web-Loops-Lab
tCarina c6e5afe
finished second smallest
tCarina 5aa6c8e
finished arrays w loops
tCarina e503e4b
finished five loops
tCarina 82f4f5f
Finished FizzBuzz 1 & 2
tCarina 631ae5d
finished range problems
tCarina 43b43a9
finished target questions
tCarina 80a977b
complete
tCarina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,14 @@ | |
* @returns {Array} - ["I!", "am!", "a!", "happy!", "array!"] | ||
*/ | ||
|
||
function shoutForLoop() {} | ||
function shoutForLoop(array){ | ||
let newArray = [] | ||
for(let i = 0; i < array.length; i++){ | ||
newArray.push(array[i] + "!") | ||
} | ||
return newArray | ||
}; | ||
|
||
/** | ||
* Takes in an array and returns a new array with element | ||
* getting a ! added to the end. | ||
|
@@ -15,7 +22,15 @@ function shoutForLoop() {} | |
* @return {Array} - ["I!", "am!", "a!", "happy!", "array!"] | ||
*/ | ||
|
||
function shoutWhileLoop() {} | ||
function shoutWhileLoop(array) { | ||
let newArray = [] | ||
let i = 0 | ||
while (i < array.length){ | ||
newArray.push(array[i] + "!") | ||
i++; | ||
} | ||
return newArray | ||
} | ||
|
||
/** | ||
* Takes in an array and returns a new array with element | ||
|
@@ -25,39 +40,75 @@ function shoutWhileLoop() {} | |
* @returns {Array} - ["I!", "am!", "a!", "happy!", "array!"] | ||
*/ | ||
|
||
function shoutForOfLoop() {} | ||
function shoutForOfLoop(array) { | ||
let newArray = [] | ||
for (let i of array){ | ||
newArray.push(i + "!") | ||
i++; | ||
} | ||
return newArray; | ||
} | ||
|
||
/** | ||
* Takes in an array and returns the sum of all values | ||
* @param {number[]} nums | ||
* @returns {number} sum | ||
*/ | ||
|
||
function sumArray() {} | ||
const sumArray = (nums) => { | ||
let sum = 0; | ||
for(let i = 0; i < nums.length; i++){ | ||
sum += nums[i]; | ||
} | ||
return sum; | ||
} | ||
|
||
/** | ||
* Takes in an array and returns an array of all the odd valued elements | ||
* @param {number[]} nums | ||
* @returns {array} odds | ||
*/ | ||
|
||
function oddArray() {} | ||
function oddArray(nums) { | ||
let newArray = []; | ||
for (let i = 0; i < nums.length; i++){ | ||
if (nums[i] % 2 === 1){ | ||
newArray.push(nums[i])} | ||
} | ||
return newArray | ||
} | ||
|
||
/** | ||
* Takes in an array and returns an array of all the even valued elements | ||
* @param {number[]} nums | ||
* @returns {array} evens | ||
*/ | ||
|
||
function evenArray() {} | ||
function evenArray(nums) { | ||
let newArray = []; | ||
for (let i = 0; i < nums.length; i++){ | ||
if (nums[i] % 2 === 0){ | ||
newArray.push(nums[i]) | ||
} | ||
} | ||
return newArray | ||
} | ||
|
||
/** | ||
* Takes in array and returns the smallest number in the array | ||
* @param {number[]} nums | ||
* @returns {number} smallest value | ||
*/ | ||
|
||
function findSmallest() {} | ||
function findSmallest(nums) { | ||
let smallestNum = nums[0]; | ||
for (let i = 0; i < nums.length; i++){ | ||
if (nums[i] < smallestNum){ | ||
smallestNum = nums[i] | ||
} | ||
} | ||
return smallestNum | ||
} | ||
|
||
/** | ||
* Takes in array and returns the second smallest number in the array | ||
|
@@ -66,15 +117,38 @@ function findSmallest() {} | |
* @returns {number} second smallest value | ||
*/ | ||
|
||
function findSecondSmallest() {} | ||
function findSecondSmallest(nums) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think about how you can use your findSmallest function to find this answer |
||
let sSmallest = Infinity | ||
let smallest = Infinity | ||
for(let i = 0; i < nums.length; i++){ | ||
if(nums[i] < smallest){ | ||
sSmallest = smallest | ||
smallest = nums[i] | ||
} else if (nums[i] < sSmallest && nums[i] > smallest){ | ||
sSmallest = nums[i] | ||
} | ||
} return sSmallest | ||
} | ||
|
||
|
||
/** | ||
* Takes in array and returns the second largest number in the array | ||
* @param {number[]} nums | ||
* @returns {number} second largest value | ||
*/ | ||
|
||
function findSecondLargest() {} | ||
function findSecondLargest(nums) { | ||
let largest = -Infinity | ||
let sLargest = -Infinity | ||
for(let i = 0; i < nums.length; i++){ | ||
if(nums[i] > largest){ | ||
sLargest = largest | ||
largest = nums[i] | ||
} else if(nums[i] > sLargest && nums[i] < largest){ | ||
sLargest = nums[i] | ||
} | ||
} return sLargest | ||
} | ||
|
||
/** | ||
* Takes in array and returns an array with all the values but with no duplicates. | ||
|
@@ -83,7 +157,15 @@ function findSecondLargest() {} | |
* @returns {array} nums without the duplicates | ||
*/ | ||
// Hint: Look into the `.includes` method. | ||
function removeDups() {} | ||
function removeDups(nums) { | ||
let newArr = [] | ||
|
||
for(let i = 0; i < nums.length; i++) { | ||
if(!newArr.includes(nums[i])){ | ||
newArr.push(nums[i]) | ||
} | ||
} return newArr | ||
} | ||
|
||
module.exports = { | ||
shoutForLoop, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"for of" loops increment themselves so you don't need i++
also remember i isn't an index in a for of loop, it's the element, so this is like saying "happy"++