Hello everyone, well did this code, and i want to switch my function to a procedure ! i did try lot of things but none works ! any help ? thank you in advance !!

```
let vectors = [[7, 1, 1],[6, 0, 2], [5, 7, 0], [3, 1, 2], [2, 3 ,8], [0, 0, 0]]
function dotProduct(vector1, vector2){
let result = 0;
for(let i = 0; i < vector1.length; i++){
result += vector1[i] * vector2[i]
}
return result
}
for(let i = 0; i < vectors.length; i++){
for(let j = i + 1; j < vectors.length; j++){
if(dotProduct(vectors[i], vectors[j]) === 0){
console.log(`${vectors[i]} and ${vectors[j]} are orthogonal `)
}
}
}
```

1 Like

Can you explain what you mean by â€śprocedureâ€ť? JS doesnâ€™t have those afaik.

1 Like

Well, itâ€™s an algorithm exercise and am trying to do it with Javascript !

i did the function part, but didnâ€™t understand the procedure part ! cause thereâ€™s no procedure in JS !

**Name: Dot product**
**Description:**
**1. Write a procedure, called dot_product which calculates in the variable ps, the dot(scalar) product of v1 and v2 (v1 and v2 are vectors of IR)**
**2. Write an algorithm which determines, for n pairs of given vectors, whether two vectors of given IR are orthogonal, by calling the procedure defined in the previous question. The dot product of two orthogonal vectors is zero.**
**3. Modify the previous algorithm if you use a dot_product function instead of a procedure.**

1 Like

These words mean different things in different languages. What language are you coming from?

1 Like

If I remember from my Pascal days, a procedure just did things whereas function *could* do things but returned something. So, I guess in JS terms, a procedure would just be an impure function who doesnâ€™t return anything but modifies one of its inputs.

1 Like

It would not even have to modify an input. It could just reference it in some way.

Itâ€™s like asking, â€śHow do I fill the gas tank on my electric car?â€ť Itâ€™s referencing a different paradigm that doesnâ€™t apply here.

Itâ€™s an algorithm course, thatâ€™s the only thing i know, but yes itâ€™s true that it looks like pascal or delphi, even thank you for you help i will try the function without return !

Youâ€™re welcome to redo the problem, but Iâ€™m not sure how much value there is in that - thatâ€™s just emphasizing a distinction that doesnâ€™t exist in JS.

The real value in doing an algorithm problem is learning the algorithm, not getting into the nitty gritty of syntax.