map-function

“this” is undefined inside map function Reactjs

梦想的初衷 提交于 2019-11-26 10:17:58
I'm working with Reactjs, writing a menu component. "use strict"; var React = require("react"); var Menus = React.createClass({ item_url: function (item,categories,articles) { console.log('afdasfasfasdfasdf'); var url='XXX'; if (item.type == 1) { url = item.categoryId == null ? 'javascript:void(0)' : path('buex_portal_browse_category', {slug: categories[item.categoryId].slug}); } else if (item.type == 2) { url = item.articleId == null ? 'javascript:void(0)' : path('buex_portal_view_article', {slug: articles[item.articleId].slug, id: item.articleId}); } else { url = item.url; } return url; },

Map function in MATLAB?

时光总嘲笑我的痴心妄想 提交于 2019-11-26 10:15:40
问题 I\'m a little surprised that MATLAB doesn\'t have a Map function, so I hacked one together myself since it\'s something I can\'t live without. Is there a better version out there? Is there a somewhat-standard functional programming library for MATLAB out there that I\'m missing? function results = map(f,list) % why doesn\'t MATLAB have a Map function? results = zeros(1,length(list)); for k = 1:length(list) results(1,k) = f(list(k)); end end usage would be e.g. map( @(x)x^2,1:10) 回答1: The

Mapping a function on the values of a map in Clojure

那年仲夏 提交于 2019-11-26 10:07:56
问题 I want to transform one map of values to another map with the same keys but with a function applied to the values. I would think there was a function for doing this in the clojure api, but I have been unable to find it. Here\'s an example implementation of what I\'m looking for (defn map-function-on-map-vals [m f] (reduce (fn [altered-map [k v]] (assoc altered-map k (f v))) {} m)) (println (map-function-on-map-vals {:a \"test\" :b \"testing\"} #(.toUpperCase %))) {:b TESTING, :a TEST} Does

Why do generators not support map()?

梦想与她 提交于 2019-11-26 08:36:40
问题 It seems utterly natural to me that generators, which function very much like Arrays, should support the very basic list operations, like map() , filter() , and reduce() . Am I missing something? I wrote the code for map and it seems simple enough, but it would be much better to have all the functions embedded in all the generators: let fancyGen = g => { let rv = function*() { for (let x of g) yield x; } rv.map = function*(p) { for (let x of g) yield p(x); } return rv; } I\'m new to

map function for objects (instead of arrays)

こ雲淡風輕ζ 提交于 2019-11-26 01:27:58
问题 I have an object: myObject = { \'a\': 1, \'b\': 2, \'c\': 3 } I am looking for a native method, similar to Array.prototype.map that would be used as follows: newObject = myObject.map(function (value, label) { return value * value; }); // newObject is now { \'a\': 1, \'b\': 4, \'c\': 9 } Does JavaScript have such a map function for objects? (I want this for Node.JS, so I don\'t care about cross-browser issues.) 回答1: There is no native map to the Object object, but how about this: var myObject

Understanding the map function

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 01:24:18
问题 map(function, iterable, ...) Apply function to every item of iterable and return a list of the results. If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel. If one iterable is shorter than another it is assumed to be extended with None items. If function is None , the identity function is assumed; if there are multiple arguments, map() returns a list consisting of tuples containing the corresponding

“this” is undefined inside map function Reactjs

你说的曾经没有我的故事 提交于 2019-11-26 01:14:18
问题 I\'m working with Reactjs, writing a menu component. \"use strict\"; var React = require(\"react\"); var Menus = React.createClass({ item_url: function (item,categories,articles) { console.log(\'afdasfasfasdfasdf\'); var url=\'XXX\'; if (item.type == 1) { url = item.categoryId == null ? \'javascript:void(0)\' : path(\'buex_portal_browse_category\', {slug: categories[item.categoryId].slug}); } else if (item.type == 2) { url = item.articleId == null ? \'javascript:void(0)\' : path(\'buex_portal

Getting a map() to return a list in Python 3.x

好久不见. 提交于 2019-11-25 23:58:11
问题 I\'m trying to map a list into hex, and then use the list elsewhere. In python 2.6, this was easy: A: Python 2.6: >>> map(chr, [66, 53, 0, 94]) [\'B\', \'5\', \'\\x00\', \'^\'] However, in Python 3.1, the above returns a map object. B: Python 3.1: >>> map(chr, [66, 53, 0, 94]) <map object at 0x00AF5570> How do I retrieve the mapped list (as in A above) on Python 3.x? Alternatively, is there a better way of doing this? My initial list object has around 45 items and id like to convert them to

JavaScript “new Array(n)” and “Array.prototype.map” weirdness

眉间皱痕 提交于 2019-11-25 23:05:30
问题 I\'ve observed this in Firefox-3.5.7/Firebug-1.5.3 and Firefox-3.6.16/Firebug-1.6.2 When I fire up Firebug: var x = new Array(3) console.log(x) // [undefined, undefined, undefined] var y = [undefined, undefined, undefined] console.log(y) // [undefined, undefined, undefined] console.log( x.constructor == y.constructor) // true console.log( x.map(function() { return 0; }) ) // [undefined, undefined, undefined] console.log( y.map(function() { return 0; }) ) // [0, 0, 0] What\'s going on here? Is

Prolog map procedure that applies predicate to list elements

点点圈 提交于 2019-11-25 22:58:08
问题 How do you write a Prolog procedure map(List, PredName, Result) that applies the predicate PredName(Arg, Res) to the elements of List , and returns the result in the list Result ? For example: test(N,R) :- R is N*N. ?- map([3,5,-2], test, L). L = [9,25,4] ; no 回答1: This is usually called maplist/3 and is part of the Prolog prologue. Note the different argument order! :- meta_predicate maplist(2, ?, ?). maplist(_C_2, [], []). maplist( C_2, [X|Xs], [Y|Ys]) :- call(C_2, X, Y), maplist( C_2, Xs,