This repository was archived by the owner on Jan 14, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 261
Glasgow Class 6 - Man Sang Sin - JavaScript Core 1 - Week 4 #226
Open
ManSangSin
wants to merge
14
commits into
CodeYourFuture:main
Choose a base branch
from
ManSangSin:main
base: main
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.
Conversation
This file contains hidden or 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
created the functions for first5(), sortArray(), tidyUpString() and remove().
continued with exercise 1-create-functions.
- npm test failed as loop was passing undefined when array has less than 5 items. - could use a check on array length before passing loop but slice method looks like better option (less code). - changed function to use slice method to replace loop.
- created a function to remove % symbol from number string. - created a function to remove values less than 19.5 - created a function to remove values greater than 23.5 - used the functions created to pass input string through and returned the first value using index 0 of the new array
watch -> what
- created a isPink function to check if colour of berry equals pink - passed the input string through isPink function using .every() method which should return a string based on the boolean value of .every()
- created a function to check if string contains "family" - created a function to check if string begins with "A" - completed the get settlers function by using the .filter() method to create a new array with only the name of families that are staying on planet alpha
- created a function to check if attendance is over 8 - created a function to return only first value when an array is passed - used .filter() method on input list of students to only return students with attendance greater than 8 - used .map() method to return only name
paramter -> parameter
- used .index() method to check if input string contains "code" word. - used .IndexOf() method to get the index of where "code" is situated in the string
- used .splice() method to return array without first item
- used .includes() method to return a boolean value for if transport from (input2) is in array (input1)
- used index() method with value 0 to access and return the first item of the input array
- used to map() and filter() methods with previous functions to return an array with locations available when a transport type is specified. - only the name of the location is returned
RahmaB1
reviewed
Mar 29, 2023
function sortArray() { | ||
function sortArray(inputArray) { | ||
let sortedArr = inputArray.sort(); | ||
return sortedArr; | ||
} |
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.
Well done !!
Please be aware that sort() method sorts the elements of an array and returns the reference to the same array.
Which means it will sort inputArray. To avoid this, you can try to copy the inputArray as value then sort the new array.
sortedArr = [...inputArray]; //it will copy the value of inputArray and not a reference to it.
sortedArr.sort( );
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
Hope that helps. 😊
Keep up the good work 👌👌
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
No description provided.