Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
Can anyone help me with sort fuctions written in Javascript to C# or explain me how these lines of code work

I'm trying to transtate this Javascript function to C# method.

parametrize = (obj, join = false) ->
    arrayOfArrays = _.pairs(obj).sort()

    symbol = if join then '&' else ''

    sortedParams = ''
    _.each arrayOfArrays, (value) ->
      sortedParams += "#{_.first(value)}=#{_.last(value)}" + symbol

    return sortedParams

This functions is written base on these scenarios.

  • parameters are sorted lexicographically by keys;
  • parameters are joined in the format key=value;
  • sig = MD5(parameters_value + session_secret_key);
  • the sig value is changed to the lower case.

I would like to write this function in C# and because of lack of understanding of what javascript does. If anyone could help me explaining what Javascript functions do for example would be awesome.

Thank you :)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So, in terms of understanding the JavaScript, the method just combines an object containing key-value pairs and combines them into a single string with either a space between or an ampersand. I'm assuming this method is used to send parameters with a get or post request, or with spaces for command line arguments.

// method that accepts an object and a join boolean (false by default)
parametrize = (obj, join = false) ->

// sort the obects and store as an array
arrayOfArrays = _.pairs(obj).sort()

// decide which join character to use
symbol = if join then '&' else ''

// Create the variable to return
sortedParams = ''

// loop through each of the array rows 
_.each arrayOfArrays, (value) ->
  // add each row into the string and add the joining symbol
  sortedParams += "#{_.first(value)}=#{_.last(value)}" + symbol

// Once complete, return the created string
return sortedParams

As for the c# side of things, this is all fairly rudimentary stuff. A quick google on loops, strings (including concatenation) and methods will sort you out.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda