PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, November 3, 2022

[FIXED] What is Python list(), filter(), lambda equivalent to Javascript?

 November 03, 2022     filter, javascript, lambda, list, python-3.x     No comments   

Issue

This is script in python. I want to achieve the same goal with Javascript. So the script is that

my_list = [18, 19, 20, 27, 28, 29, 38, 39, 40]

new_list = list(filter(lambda x: x + 10 in my_list or x - 10 in my_list, my_list))

What is equivalent of list(), filter(), lambda in this situation to convert Python to Javasript ?


Solution

It can be converted to JavaScript using Array.filter() and Array.includes().

const my_list = [18, 19, 20, 27, 28, 29, 38, 39, 40]

const new_list = my_list.filter(x => my_list.includes(x+10) || my_list.includes(x-10))

console.log(new_list)



Answered By - GrafiCode
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,205,810

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing