How do I apply lambda to each item in a loop?
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?
Answers
-
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. -
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.
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback