How do I apply lambda to each item in a loop?

Options

I have this snippet saved as a lambda function:

const accentedCharacters = 'áàãâäéèêëíìîïóòõôöúùûüñçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÔÖÚÙÛÜÑÇ'

const normalCharacters = 'aaaaaeeeeiiiiooooouuuuncAAAAAEEEEIIIIOOOOOUUUUNC'

let text = $var.sample.replace(/[áàãâäéèêëíìîïóòõôöúùûüñçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÔÖÚÙÛÜÑÇ]/g, match => normalCharacters.charAt(accentedCharacters.indexOf(match)))

return text

I wanna use it inside a loop to update each item. Example, I'm looping through a list and wanna use this lambda function to each item in that list. I tried using map

const accentedCharacters = 'áàãâäéèêëíìîïóòõôöúùûüñçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÔÖÚÙÛÜÑÇ'

const normalCharacters = 'aaaaaeeeeiiiiooooouuuuncAAAAAEEEEIIIIOOOOOUUUUNC'

return $var.r2array.map(item => {item.sample = item.replace(/[áàãâäéèêëíìîïóòõôöúùûüñçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÔÖÚÙÛÜÑÇ]/g, match => normalCharacters.charAt(accentedCharacters.indexOf(match)))

return item.sample})


however I keep getting this error:
["$auth must be an object","$var must be an object","$env must be an object","$input must be an object","$global must be an object","code must be a string"]

How do I fix this?

Tagged:

Answers

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    This is a neat problem! Just need a little more info. A loom would surface better the questions I have:

    1) Which item in the function stack is throwing this error?
    2) What is the exact code in the lambda?
    3) What is r2array and what does it contain before the lambda?
    4) If you just had it return $var.r2array, and did not do the map, would you get back the original data, or an error?

    Lambdas in xano are not always perfect in the way they handle complex UTF8 characters, hence the detail can matter.

    Loom videos are very full of detail, which is why they are the best practice for dealing with hard questions like this in our forums and daily office hour prep at State Change Pro.

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Options

    Hey there! Lambdas do unfortunately have trouble with accented characters, and the error you've receiving is typical of this. Consider using the "strip_accents" filter on the data instead.