London10 -Anu Thapaliya-JS1-Week4#227
London10 -Anu Thapaliya-JS1-Week4#227anuthapaliy wants to merge 3 commits intoCodeYourFuture:mainfrom
Conversation
| function findLongNameThatStartsWithA (names) { | ||
| let longName = names.find(names => names.length>7 && names.startsWith("A")); | ||
| return longName; | ||
| } |
There was a problem hiding this comment.
There's a simpler way to find words that starts with "A". Instead of startWith method, can you think of accessing first letter using array[index]?
|
|
||
| let pairsByIndex; // Complete this statement | ||
| let pairsByIndex = pairsByIndexRaw.filter((pairs) => Array.isArray(pairs) && pairs.length ===2); | ||
|
|
There was a problem hiding this comment.
This works fine. Can you make another attempt using filter() method?
| */ | ||
|
|
||
| let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; | ||
| arr.forEach(array); |
There was a problem hiding this comment.
To make your codes neater, it's a very good practice to use conditional ternary operator instead of if else chaining. If you do so, you'll have one line of code instead of line 14 to 24
| let statement = "I do not like programming"; | ||
|
|
||
| let result = ""; | ||
| let result = statement.substring(0, 5).concat(statement.substring(8, statement.length)); |
There was a problem hiding this comment.
A very very tiny mistake! you have one extra space between do and not! can you find out why?
|
|
||
| function formatPercentage() { | ||
| function formatPercentage(array) { | ||
| let input = []; |
There was a problem hiding this comment.
You don't have to define an empty array. Mapping on array instead of traditional for loop is a neater option.
| if(number>100) { | ||
| input.push("100%") | ||
| }else{ | ||
| input.push(`${Number(number.toFixed(2))}%`) |
There was a problem hiding this comment.
I recommend using Math.round() instead of toFixed(). Please see the difference. Math.round() always returns an integer and you don't have to convert it to a number
| findSafeOxygenLevel(["200%", "-21.5%", "20", "apes", "21.1%"]) | ||
| ).toEqual("21.1%"); | ||
| }); | ||
| // test("findSafeOxygenLevel function filters out invalid percentages", () => { |
There was a problem hiding this comment.
hmm, not sure why you have commented out the test
| function findSafeOxygenLevel() {} | ||
| // Some string methods that might help you here are .replace() and .substring(). | ||
| function isSafeOxygenLevel(oxygenlevel){ | ||
| return parseFloat(oxygenlevel)>19.5 && parseFloat(oxygenlevel)<23.5; |
There was a problem hiding this comment.
This one is intersting! this is not passing the third test(thet you commented:)). To pass this test, you should add a condition or use includes()method to only include strings which have %.
Or forget about parseFloat and use .replace() and .substring() and .map() obviously
| //Write your code here | ||
| } | ||
| function isBerrySafe(berry){ | ||
| if(berry=== "pink"){ |
There was a problem hiding this comment.
If you download prettier extention for JS in your VS code, it makes your codes look nicer! no extra space, etc
Also recommend using eslint js extention
| let stayingFamiliesArray = voyagers.filter(likeThisPlanet); | ||
| return stayingFamiliesArray; | ||
| }; | ||
|
|
There was a problem hiding this comment.
The logic is all correct.
worth making another attemp, only one function getSettlers() and .include() after filter()
| let sitInExam = studentAttendance.filter(isEligible); | ||
| let examNames = sitInExam.map(onlyNames); | ||
| return examNames; | ||
| }; |
There was a problem hiding this comment.
Same issue here. The logic works absolutly fine. We don't have to have the first two functions. Fewer lines are not always better. But, fewer lines are often better than more lines in terms of readability and maintainability.
| //edit code below | ||
| if (stringText) { | ||
| return stringText; | ||
| if (stringText.includes("code")) { |
There was a problem hiding this comment.
more efficient to pass magicWord instead of "code"
|
Well done for finishing JS1 week4! Really good practice of array methods and arrow function. Please let me know if any of the comments isn't clear enough |
No description provided.