Skip to content

Conversation

@Ngandec
Copy link
Contributor

@Ngandec Ngandec commented Nov 28, 2023

No description provided.

@Ngandec Ngandec force-pushed the feat/ngan-assignment branch from 1686ce5 to fb79986 Compare December 8, 2023 03:24
@gitguardian
Copy link

gitguardian bot commented Dec 8, 2023

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id Secret Commit Filename
- OpenWeatherMap Token fb79986 programming-language-for-tester-assignment/NganLe/nodejs-project/index.js View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

- Explanation: Teaches array manipulation methods.
*/
function reverseOrder(array) {
return array.reverse();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Em nên kiểm tra điều kiện là parameter array có phải là kiểu mảng không trước khi sử dụng hàm reverse(), thực tế khi viết ra 1 function thì phải xem xét việc function đó sẽ được người khác sử dụng và mình cũng ko chắc chắn được liệu người ta có input đúng data type mình yêu cầu không.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nếu không sử dụng ham reverse() thì em sẽ thực hiện giải pháp này như thế nào (chỉ dùng thuần túy for loop)

*/
function returnNumberGreaterThan10(arr) {
return arr.filter(function (value) {
return value > 10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Em có thể coi thêm Arrow function expressions. Ở dưới đã thấy em có sử dụng

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chỗ này cũng chưa validate là array này có phải là 1 array chưa toàn bộ là number hay không

- Use a switch statement to log a greeting based on the current day of the week.
- Explanation: Teaches the switch case control structure.
*/
let today = new Date().getDay();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chỗ này nên dùng const vì today sẽ là biến không cần khởi tạo hoặc gán lại giá trị mới khi chạy

*/
class Car {
constructor(model, year) {
this.model = model;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Em có thể mở rộng thêm chỗ này về keyword this trong JavaScript https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this

console.error(error);
}
}
useAsyncAwait()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useAsyncAwait() chưa có keyword await, đối với keyword await thì nó luôn được sử dụng bên trong 1 function vì thế chỗ này sẽ hơi tricky trong việc implement để mô phỏng keyword await

async function useAsyncAwait() {
    try {
        const message = await new Promise(function (resolve, reject) {
            setTimeout(() => {
                resolve('Success!');
            }, 2000);
        })
        console.log(message);
    } catch (error) {
        console.error(error);
    }
}
useAsyncAwait();
// Lúc này thì console sẽ in ra "a", trong khi mình muốn là phải in ra success trước;
console.log("a");
async function useAsyncAwait() {
    try {
        const message = await new Promise(function (resolve, reject) {
            setTimeout(() => {
                resolve('Success!');
            }, 2000);
        })
        console.log(message);
    } catch (error) {
        console.error(error);
    }
}
// Mình sẽ tạm wrap lại bằng 1 immediately invoked function
(async () => {
    await useAsyncAwait()
    console.log("a");
})();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chỗ này em có khởi tạo await ở

const message = await new Promise

Theo ý của anh thì em sẽ viết lại là

function useAsyncAwait() {
    return new Promise(function (resolve) {
        setTimeout(() => {
            resolve('Success!');
        }, 2000);
    })
}
(async () => {
    await useAsyncAwait()
    console.log("a");
})();

function countChar(str, char) {
let count = 0;
for (let i = 0; i < str.length; i++) {
if (str[i] == char) count++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

str[i] == char sẽ sai khi so sánh trường hợp input là số console.log(countChar('hello1hello1', 1));

function replaceDivisible(number) {
let outputStr = '';
for (let i = 1; i <= number; i++) {
if (i % 3 === 0 && i % 5 !== 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nên khởi tạo 1 biến kiểu bool để đại diện cho "i % 3 === 0 && i % 5 !== 0" ví dụ

const isPrintFizz = i % 3 === 0 && i % 5 !== 0;
if (isPrintFizz) outputStr += 'Fizz';

Khi đó code sẽ dễ đọc và dễ hiểu hơn

})
}
function createActiveProfileFile() {
const fs = require('fs');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Những lệnh liên quan require/import thì luôn đưa lên đầu file. Import là syntax của JavaScript ES6

}
// ***Function to fetch weather data using the request library
function fetchWeatherWithRequest(lat, lon, callback) {
const url = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${apiKey}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL này ở 3 function đều như nhau thì nên đưa ra bên ngoài và khai báo chung biến const url;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chỗ này url nhưng lại chứa tham số lat, lon được truyền vào khi gọi function thì làm sao để đưa ra bên ngoài để khai báo chung được ạ?

- Explanation: Use closures or the new `#` syntax for private fields.
*/
class Encapsulation {
#privateProperties;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thực tế thì ở JavaScript và Python hoặc những ngôn ngữ dạng interpreted language thì khái niệm private không thật sự private, nó chỉ là quy định về syntax để mọi người cùng hiểu đó là thuộc tính có tính private

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants