How to switch from a function to a procedure?

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.