Questions tagged [map-function]

Higher-order function "map" transforms a collection by applying a given function to each element in it. USE [maps] for geography, [map] or [dictionary] for data types.

A map function is a higher-order function that applies a function to each element in a list, building a list of the results. Examples include map in Python, Scheme, Haskell and Scala, Stream.map in Java 8, array_map in PHP, and std::transform in C++.

A generalized map works with some general type of a collection, applying a function to each element in the collection and building the collection (of the same general type) of the results. An example is fmap in Haskell, etc.

For questions about geography, use the tag instead.

For questions about data types, use the tag instead, which is a synonym tag for .

829 questions
-2
votes
1 answer

How to convert this loop to a map?

How could i get the same result with a map? i'm a beginner trying to learn how maps relate to iteration. Is it possible to put this loop into a map? user_list = [int(input("what is the fist integer? "))] for i in user_list: if i < 100: …
qjrob
  • 1
-2
votes
2 answers

React Js : How can i use index number to disable button ( if index = 4 then disable button )

enter image description here i have to create a component where one person can add upto 4 addresses for doing this i have used slice(0,4) in map function but i have to make button disabled when 4 addresses are entered How can i do this i need a…
-2
votes
4 answers

Python how to apply map function on elements of list if possible?

I have a list that looks like this ['111', '222', '333', 'xxx', '3233'] I'd like to change all elements to int if possible. In this case, xxx is not a digit. So how can I ignore 'xxx' and change all other elements to int? I can do this with a for…
user8314628
  • 1,952
  • 2
  • 22
  • 46
-2
votes
3 answers

i have a python list, using map function is omitting the first zero of the list

I have this code in python, when I print the last line, it is giving an output "11100101100". I'm expecting the output,"011100101100". Notice that the output starts with 1 and not 0. although the variable gamma_sum_list is a list containing 12…
-2
votes
2 answers

Can someone please breakdown this function step by step and explain me what it is doing?

adjacentElementsProduct is a function that takes an array as an input and we need to find and return the adjacent elements whose product is greater among all the adjacent elements. function adjacentElementsProduct(arr) { return…
EhtU
  • 41
  • 4
-2
votes
1 answer

For some reason I am getting: fetch(...).then(...).then(...).map is not a function

function getResults(querySearch) { api.pageNum += 1; refs.list.innerHTML = ''; const imgBlock = fetch( `https://pixabay.com/api/?image_type=photo&orientation=horizontal&q=${querySearch}&page=${api.pageNum}&per_page=12&key=${api.key}`, ) …
ElMuchacho
  • 300
  • 1
  • 12
-2
votes
3 answers

Create a simple rank array using map function (JavaScript)

So essentially I have a JSON that it's in the format as so: JSON= [ {username: foo, score: 12343}, {username: bar, score: 9432}, {username: foo-bar, score: 402, ... ] I know that the JSON that I am getting back is already rank from highest to…
Alejandro
  • 2,266
  • 6
  • 35
  • 63
-2
votes
1 answer

EAN13 checksum class for python 3 using comprehension list

I'm trying to change this python 2 class to make it works in python 3 But unfortunatly i'm stuck with comprehension list Here is the original class: class GTIN(object): def __init__(self, barcode=''): self.barcode = barcode def…
Andronaute
  • 379
  • 3
  • 12
-2
votes
1 answer

python map function does not work

This is the code I edit on an editor and compile on a shell. If I enter the integer 19, when I print out c, it is still ['1','9'] instead of the [1,9] I want. I tried this on the interactive interpreter instead of compiling a python file and it…
user12551
  • 145
  • 1
  • 2
  • 9
-3
votes
0 answers

google street view studio "Sorry, no imagery here" problem

Does anyone know how to fix this issue? Everytime I zoom out, the tiles appear without fail no matter what network connection I have or what browser I use. This video sums up whats happening. Any help greatly appreciated, thank you.…
-3
votes
2 answers

How do I reduce list of dictionaries

I have a list of dictionaries in python. For example mylist = [ {'a': 'x', 'b':'y', 'c':'z'}, {'a':'e','b':'f','c':'g'}, {'a':'h','b':'i','c':'j'} ] how can i map this into mynewlist = [ {'a':'x'}, {'a','e'}, …
-3
votes
1 answer

target ever second word in a string using map function

Apply the map() function to the variable str so that every second word in the string is converted to uppercase. in javascript. str = "hello my name is jon and i live in. canada."
-3
votes
2 answers

How to compare/match id's in two seperate arrays, and retrieve some data into one object in javascript?

I have the following values - const r = [{ id: 2, car: 'toyota}, {id: 1, car:'honda'}] const s = [{ id: 2, name: 'Samuel'},{id: 1, name: 'James'}] I want to match the arrays based on id and add name to each corresponding matched object id. const…
Kashyap
  • 85
  • 2
  • 9
-3
votes
3 answers

TypeError: food.map is not a function in Reactjs

I am new to Reactjs. I am using React hooks and axios to fetch an api of a single post data from its id. I called the api and passed the data into child components using props through spread operator. The server runs but on the page it renders the…
Reactoo
  • 916
  • 2
  • 12
  • 40
-3
votes
1 answer

How to create an array of objects having values as objects from an array that has been created in javascript?

I have an array whose elements are in string format, like this: somearray = [object, object, object] where each object has a fname: "abc", lname: "pqr", age: 31 I am trying to create an object from this array whose variable I have declared as var…
d33a
  • 690
  • 1
  • 14
  • 39
1 2 3
55
56