Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.

Glasgow Class 6 - Man Sang Sin - JavaScript Core 1 - Week 4 #226

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

ManSangSin
Copy link

No description provided.

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
function sortArray() {
function sortArray(inputArray) {
let sortedArr = inputArray.sort();
return sortedArr;
}
Copy link

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.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants