[{"data":1,"prerenderedAt":3538},["ShallowReactive",2],{"page-\u002Fjs\u002F13-higher-order-functions":3},{"id":4,"title":5,"body":6,"description":30,"extension":3532,"meta":3533,"navigation":90,"path":3534,"seo":3535,"stem":3536,"__hash__":3537},"content\u002Fjs\u002F13-higher-order-functions.md","13 — Higher-Order Functions",{"type":7,"value":8,"toc":3508},"minimark",[9,13,246,419,542,677,821,1079,1211,1353,1455,1546,1788,1922,2078,2382,2554,2733,2900,3146,3351,3504],[10,11,5],"h1",{"id":12},"_13-higher-order-functions",[14,15,17,22,151,194],"question-wrapper",{"language":16},"javascript",[18,19,21],"h3",{"id":20},"q1-what-does-this-log","Q1. What does this log?",[23,24,25],"code-wrapper",{"language":16},[26,27,31],"pre",{"className":28,"code":29,"language":16,"meta":30,"style":30},"language-javascript shiki shiki-themes github-light github-dark","function applyDiscount(prices, discountFn) {\n  return prices.map(discountFn);\n}\n\nconst withTax = applyDiscount([100, 200], p => p * 1.1);\nconsole.log(withTax);\n","",[32,33,34,64,79,85,92,139],"code",{"__ignoreMap":30},[35,36,39,43,47,51,55,58,61],"span",{"class":37,"line":38},"line",1,[35,40,42],{"class":41},"svdQ7","function",[35,44,46],{"class":45},"sIsaT"," applyDiscount",[35,48,50],{"class":49},"ssxIu","(",[35,52,54],{"class":53},"sCrzJ","prices",[35,56,57],{"class":49},", ",[35,59,60],{"class":53},"discountFn",[35,62,63],{"class":49},") {\n",[35,65,67,70,73,76],{"class":37,"line":66},2,[35,68,69],{"class":41},"  return",[35,71,72],{"class":49}," prices.",[35,74,75],{"class":45},"map",[35,77,78],{"class":49},"(discountFn);\n",[35,80,82],{"class":37,"line":81},3,[35,83,84],{"class":49},"}\n",[35,86,88],{"class":37,"line":87},4,[35,89,91],{"emptyLinePlaceholder":90},true,"\n",[35,93,95,98,102,105,107,110,113,115,118,121,124,127,130,133,136],{"class":37,"line":94},5,[35,96,97],{"class":41},"const",[35,99,101],{"class":100},"snvgF"," withTax",[35,103,104],{"class":41}," =",[35,106,46],{"class":45},[35,108,109],{"class":49},"([",[35,111,112],{"class":100},"100",[35,114,57],{"class":49},[35,116,117],{"class":100},"200",[35,119,120],{"class":49},"], ",[35,122,123],{"class":53},"p",[35,125,126],{"class":41}," =>",[35,128,129],{"class":49}," p ",[35,131,132],{"class":41},"*",[35,134,135],{"class":100}," 1.1",[35,137,138],{"class":49},");\n",[35,140,142,145,148],{"class":37,"line":141},6,[35,143,144],{"class":49},"console.",[35,146,147],{"class":45},"log",[35,149,150],{"class":49},"(withTax);\n",[152,153,156,169,177,186],"ul",{"className":154},[155],"contains-task-list",[157,158,161,165,166],"li",{"className":159},[160],"task-list-item",[162,163],"input",{"disabled":90,"type":164},"checkbox"," ",[35,167,168],{},"110.00000000000001, 220.00000000000002",[157,170,172,165,174],{"className":171},[160],[162,173],{"disabled":90,"type":164},[35,175,176],{},"110, 220",[157,178,180,182,183,185],{"className":179},[160],[162,181],{"disabled":90,"type":164}," Throws a TypeError because ",[32,184,60],{}," isn't a built-in method",[157,187,189,165,191],{"className":188},[160],[162,190],{"disabled":90,"type":164},[35,192,193],{},"100, 200",[195,196,197,201,210],"details",{},[198,199,200],"summary",{},"Show Answer",[123,202,203,207,208],{},[204,205,206],"strong",{},"Answer:"," A — ",[35,209,168],{},[123,211,212,165,215,218,219,222,223,225,226,229,230,233,234,237,238,241,242,245],{},[204,213,214],{},"Explanation:",[32,216,217],{},"applyDiscount"," is a ",[204,220,221],{},"higher-order function"," — it accepts another function as an argument and delegates the transformation to it via ",[32,224,75],{},". The math itself hits a classic floating-point trap: ",[32,227,228],{},"100 * 1.1"," and ",[32,231,232],{},"200 * 1.1"," can't be represented exactly in IEEE-754 double precision, so the results carry tiny rounding error instead of the clean ",[32,235,236],{},"110","\u002F",[32,239,240],{},"220"," you'd expect. ",[204,243,244],{},"Debug:"," this is why money math is usually done in integer cents or with a decimal library, not floating-point multiplication.",[14,247,248,252,353,383],{"language":16},[18,249,251],{"id":250},"q2-what-does-this-log","Q2. What does this log?",[23,253,254],{"language":16},[26,255,257],{"className":28,"code":256,"language":16,"meta":30,"style":30},"function multiplyBy(factor) {\n  return function (n) {\n    return n * factor;\n  };\n}\n\nconst double = multiplyBy(2);\nconsole.log(double(5));\n",[32,258,259,273,288,301,306,310,314,333],{"__ignoreMap":30},[35,260,261,263,266,268,271],{"class":37,"line":38},[35,262,42],{"class":41},[35,264,265],{"class":45}," multiplyBy",[35,267,50],{"class":49},[35,269,270],{"class":53},"factor",[35,272,63],{"class":49},[35,274,275,277,280,283,286],{"class":37,"line":66},[35,276,69],{"class":41},[35,278,279],{"class":41}," function",[35,281,282],{"class":49}," (",[35,284,285],{"class":53},"n",[35,287,63],{"class":49},[35,289,290,293,296,298],{"class":37,"line":81},[35,291,292],{"class":41},"    return",[35,294,295],{"class":49}," n ",[35,297,132],{"class":41},[35,299,300],{"class":49}," factor;\n",[35,302,303],{"class":37,"line":87},[35,304,305],{"class":49},"  };\n",[35,307,308],{"class":37,"line":94},[35,309,84],{"class":49},[35,311,312],{"class":37,"line":141},[35,313,91],{"emptyLinePlaceholder":90},[35,315,317,319,322,324,326,328,331],{"class":37,"line":316},7,[35,318,97],{"class":41},[35,320,321],{"class":100}," double",[35,323,104],{"class":41},[35,325,265],{"class":45},[35,327,50],{"class":49},[35,329,330],{"class":100},"2",[35,332,138],{"class":49},[35,334,336,338,340,342,345,347,350],{"class":37,"line":335},8,[35,337,144],{"class":49},[35,339,147],{"class":45},[35,341,50],{"class":49},[35,343,344],{"class":45},"double",[35,346,50],{"class":49},[35,348,349],{"class":100},"5",[35,351,352],{"class":49},"));\n",[152,354,356,362,371,377],{"className":355},[155],[157,357,359,361],{"className":358},[160],[162,360],{"disabled":90,"type":164}," 10",[157,363,365,182,367,370],{"className":364},[160],[162,366],{"disabled":90,"type":164},[32,368,369],{},"multiplyBy"," doesn't return a callable value",[157,372,374,376],{"className":373},[160],[162,375],{"disabled":90,"type":164}," NaN",[157,378,380,382],{"className":379},[160],[162,381],{"disabled":90,"type":164}," 7 (5 + 2)",[195,384,385,387,392],{},[198,386,200],{},[123,388,389,391],{},[204,390,206],{}," A — 10",[123,393,394,165,396,398,399,401,402,404,405,407,408,410,411,414,415,418],{},[204,395,214],{},[32,397,369],{}," is a factory: it returns a new function that closes over ",[32,400,270],{},". ",[32,403,344],{}," is that returned function with ",[32,406,270],{}," fixed at ",[32,409,330],{},", so calling ",[32,412,413],{},"double(5)"," computes ",[32,416,417],{},"5 * 2 = 10",". This \"function returning a function\" shape is the foundation both of closures and of currying, covered later in this quiz.",[14,420,421,425,482,513],{"language":16},[18,422,424],{"id":423},"q3-what-does-this-log","Q3. What does this log?",[23,426,427],{"language":16},[26,428,430],{"className":28,"code":429,"language":16,"meta":30,"style":30},"const names = ['ana', 'bob'];\nconsole.log(names.map(n => n.toUpperCase()));\n",[32,431,432,456],{"__ignoreMap":30},[35,433,434,436,439,441,444,448,450,453],{"class":37,"line":38},[35,435,97],{"class":41},[35,437,438],{"class":100}," names",[35,440,104],{"class":41},[35,442,443],{"class":49}," [",[35,445,447],{"class":446},"sJ6F3","'ana'",[35,449,57],{"class":49},[35,451,452],{"class":446},"'bob'",[35,454,455],{"class":49},"];\n",[35,457,458,460,462,465,467,469,471,473,476,479],{"class":37,"line":66},[35,459,144],{"class":49},[35,461,147],{"class":45},[35,463,464],{"class":49},"(names.",[35,466,75],{"class":45},[35,468,50],{"class":49},[35,470,285],{"class":53},[35,472,126],{"class":41},[35,474,475],{"class":49}," n.",[35,477,478],{"class":45},"toUpperCase",[35,480,481],{"class":49},"()));\n",[152,483,485,493,501,507],{"className":484},[155],[157,486,488,165,490],{"className":487},[160],[162,489],{"disabled":90,"type":164},[35,491,492],{},"'ANA', 'BOB'",[157,494,496,165,498],{"className":495},[160],[162,497],{"disabled":90,"type":164},[35,499,500],{},"'ana', 'bob'",[157,502,504,506],{"className":503},[160],[162,505],{"disabled":90,"type":164}," 'ANA,BOB'",[157,508,510,512],{"className":509},[160],[162,511],{"disabled":90,"type":164}," Throws a TypeError",[195,514,515,517,523],{},[198,516,200],{},[123,518,519,207,521],{},[204,520,206],{},[35,522,492],{},[123,524,525,165,527,529,530,533,534,537,538,541],{},[204,526,214],{},[32,528,75],{}," creates a ",[204,531,532],{},"new array"," by applying the callback to every element and collecting the return values — it never mutates ",[32,535,536],{},"names",". Each string's ",[32,539,540],{},".toUpperCase()"," produces a new uppercase string, and those are collected in order into the result array.",[14,543,544,548,617,650],{"language":16},[18,545,547],{"id":546},"q4-what-does-this-log","Q4. What does this log?",[23,549,550],{"language":16},[26,551,553],{"className":28,"code":552,"language":16,"meta":30,"style":30},"const nums = [1, 2, 3, 4, 5];\nconsole.log(nums.filter(n => n > 3));\n",[32,554,555,589],{"__ignoreMap":30},[35,556,557,559,562,564,566,569,571,573,575,578,580,583,585,587],{"class":37,"line":38},[35,558,97],{"class":41},[35,560,561],{"class":100}," nums",[35,563,104],{"class":41},[35,565,443],{"class":49},[35,567,568],{"class":100},"1",[35,570,57],{"class":49},[35,572,330],{"class":100},[35,574,57],{"class":49},[35,576,577],{"class":100},"3",[35,579,57],{"class":49},[35,581,582],{"class":100},"4",[35,584,57],{"class":49},[35,586,349],{"class":100},[35,588,455],{"class":49},[35,590,591,593,595,598,601,603,605,607,609,612,615],{"class":37,"line":66},[35,592,144],{"class":49},[35,594,147],{"class":45},[35,596,597],{"class":49},"(nums.",[35,599,600],{"class":45},"filter",[35,602,50],{"class":49},[35,604,285],{"class":53},[35,606,126],{"class":41},[35,608,295],{"class":49},[35,610,611],{"class":41},">",[35,613,614],{"class":100}," 3",[35,616,352],{"class":49},[152,618,620,628,636,642],{"className":619},[155],[157,621,623,165,625],{"className":622},[160],[162,624],{"disabled":90,"type":164},[35,626,627],{},"4, 5",[157,629,631,165,633],{"className":630},[160],[162,632],{"disabled":90,"type":164},[35,634,635],{},"1, 2, 3",[157,637,639,641],{"className":638},[160],[162,640],{"disabled":90,"type":164}," true",[157,643,645,165,647],{"className":644},[160],[162,646],{"disabled":90,"type":164},[35,648,649],{},"false, false, false, true, true",[195,651,652,654,660],{},[198,653,200],{},[123,655,656,207,658],{},[204,657,206],{},[35,659,627],{},[123,661,662,165,664,666,667,669,670,229,673,676],{},[204,663,214],{},[32,665,600],{}," keeps only the elements for which the predicate returns a truthy value, returning a new array of just those elements — not the boolean results themselves (that would be ",[32,668,75],{},"'s job). ",[32,671,672],{},"4 > 3",[32,674,675],{},"5 > 3"," are the only true cases.",[14,678,679,683,761,789],{"language":16},[18,680,682],{"id":681},"q5-what-does-this-log","Q5. What does this log?",[23,684,685],{"language":16},[26,686,688],{"className":28,"code":687,"language":16,"meta":30,"style":30},"const cart = [{ price: 10 }, { price: 20 }, { price: 5 }];\nconsole.log(cart.reduce((sum, item) => sum + item.price, 0));\n",[32,689,690,718],{"__ignoreMap":30},[35,691,692,694,697,699,702,705,708,711,713,715],{"class":37,"line":38},[35,693,97],{"class":41},[35,695,696],{"class":100}," cart",[35,698,104],{"class":41},[35,700,701],{"class":49}," [{ price: ",[35,703,704],{"class":100},"10",[35,706,707],{"class":49}," }, { price: ",[35,709,710],{"class":100},"20",[35,712,707],{"class":49},[35,714,349],{"class":100},[35,716,717],{"class":49}," }];\n",[35,719,720,722,724,727,730,733,736,738,741,744,747,750,753,756,759],{"class":37,"line":66},[35,721,144],{"class":49},[35,723,147],{"class":45},[35,725,726],{"class":49},"(cart.",[35,728,729],{"class":45},"reduce",[35,731,732],{"class":49},"((",[35,734,735],{"class":53},"sum",[35,737,57],{"class":49},[35,739,740],{"class":53},"item",[35,742,743],{"class":49},") ",[35,745,746],{"class":41},"=>",[35,748,749],{"class":49}," sum ",[35,751,752],{"class":41},"+",[35,754,755],{"class":49}," item.price, ",[35,757,758],{"class":100},"0",[35,760,352],{"class":49},[152,762,764,770,776,781],{"className":763},[155],[157,765,767,769],{"className":766},[160],[162,768],{"disabled":90,"type":164}," 35",[157,771,773,775],{"className":772},[160],[162,774],{"disabled":90,"type":164}," 0",[157,777,779,376],{"className":778},[160],[162,780],{"disabled":90,"type":164},[157,782,784,165,786],{"className":783},[160],[162,785],{"disabled":90,"type":164},[35,787,788],{},"10, 20, 5",[195,790,791,793,798],{},[198,792,200],{},[123,794,795,797],{},[204,796,206],{}," A — 35",[123,799,800,165,802,804,805,807,808,810,811,57,814,57,817,820],{},[204,801,214],{},[32,803,729],{}," folds the array down to a single value by repeatedly applying the callback, carrying an accumulator (",[32,806,735],{},", starting at the initial value ",[32,809,758],{},") forward. ",[32,812,813],{},"0 + 10 = 10",[32,815,816],{},"10 + 20 = 30",[32,818,819],{},"30 + 5 = 35"," — the final accumulator is what's returned.",[14,822,823,827,999,1037],{"language":16},[18,824,826],{"id":825},"q6-what-does-this-log","Q6. What does this log?",[23,828,829],{"language":16},[26,830,832],{"className":28,"code":831,"language":16,"meta":30,"style":30},"const orders = [\n  { amount: 100, status: 'paid' },\n  { amount: 50, status: 'pending' },\n  { amount: 200, status: 'paid' }\n];\n\nconst total = orders\n  .filter(o => o.status === 'paid')\n  .map(o => o.amount)\n  .reduce((a, b) => a + b, 0);\n\nconsole.log(total);\n",[32,833,834,846,862,876,889,893,897,909,935,951,984,989],{"__ignoreMap":30},[35,835,836,838,841,843],{"class":37,"line":38},[35,837,97],{"class":41},[35,839,840],{"class":100}," orders",[35,842,104],{"class":41},[35,844,845],{"class":49}," [\n",[35,847,848,851,853,856,859],{"class":37,"line":66},[35,849,850],{"class":49},"  { amount: ",[35,852,112],{"class":100},[35,854,855],{"class":49},", status: ",[35,857,858],{"class":446},"'paid'",[35,860,861],{"class":49}," },\n",[35,863,864,866,869,871,874],{"class":37,"line":81},[35,865,850],{"class":49},[35,867,868],{"class":100},"50",[35,870,855],{"class":49},[35,872,873],{"class":446},"'pending'",[35,875,861],{"class":49},[35,877,878,880,882,884,886],{"class":37,"line":87},[35,879,850],{"class":49},[35,881,117],{"class":100},[35,883,855],{"class":49},[35,885,858],{"class":446},[35,887,888],{"class":49}," }\n",[35,890,891],{"class":37,"line":94},[35,892,455],{"class":49},[35,894,895],{"class":37,"line":141},[35,896,91],{"emptyLinePlaceholder":90},[35,898,899,901,904,906],{"class":37,"line":316},[35,900,97],{"class":41},[35,902,903],{"class":100}," total",[35,905,104],{"class":41},[35,907,908],{"class":49}," orders\n",[35,910,911,914,916,918,921,923,926,929,932],{"class":37,"line":335},[35,912,913],{"class":49},"  .",[35,915,600],{"class":45},[35,917,50],{"class":49},[35,919,920],{"class":53},"o",[35,922,126],{"class":41},[35,924,925],{"class":49}," o.status ",[35,927,928],{"class":41},"===",[35,930,931],{"class":446}," 'paid'",[35,933,934],{"class":49},")\n",[35,936,938,940,942,944,946,948],{"class":37,"line":937},9,[35,939,913],{"class":49},[35,941,75],{"class":45},[35,943,50],{"class":49},[35,945,920],{"class":53},[35,947,126],{"class":41},[35,949,950],{"class":49}," o.amount)\n",[35,952,954,956,958,960,963,965,968,970,972,975,977,980,982],{"class":37,"line":953},10,[35,955,913],{"class":49},[35,957,729],{"class":45},[35,959,732],{"class":49},[35,961,962],{"class":53},"a",[35,964,57],{"class":49},[35,966,967],{"class":53},"b",[35,969,743],{"class":49},[35,971,746],{"class":41},[35,973,974],{"class":49}," a ",[35,976,752],{"class":41},[35,978,979],{"class":49}," b, ",[35,981,758],{"class":100},[35,983,138],{"class":49},[35,985,987],{"class":37,"line":986},11,[35,988,91],{"emptyLinePlaceholder":90},[35,990,992,994,996],{"class":37,"line":991},12,[35,993,144],{"class":49},[35,995,147],{"class":45},[35,997,998],{"class":49},"(total);\n",[152,1000,1002,1008,1014,1020],{"className":1001},[155],[157,1003,1005,1007],{"className":1004},[160],[162,1006],{"disabled":90,"type":164}," 300",[157,1009,1011,1013],{"className":1010},[160],[162,1012],{"disabled":90,"type":164}," 350",[157,1015,1017,1019],{"className":1016},[160],[162,1018],{"disabled":90,"type":164}," 250",[157,1021,1023,1025,1026,57,1029,1032,1033,1036],{"className":1022},[160],[162,1024],{"disabled":90,"type":164}," Throws a TypeError because you can't chain ",[32,1027,1028],{},".filter",[32,1030,1031],{},".map",", and ",[32,1034,1035],{},".reduce"," together",[195,1038,1039,1041,1046],{},[198,1040,200],{},[123,1042,1043,1045],{},[204,1044,206],{}," A — 300",[123,1047,1048,1050,1051,1054,1055,1057,1058,1060,1061,229,1063,1065,1066,1068,1069,1032,1072,1074,1075,1078],{},[204,1049,214],{}," This is a standard ",[204,1052,1053],{},"map\u002Ffilter\u002Freduce composition"," pipeline: ",[32,1056,600],{}," keeps only the two ",[32,1059,858],{}," orders (",[32,1062,112],{},[32,1064,117],{},"), ",[32,1067,75],{}," projects each down to just its ",[32,1070,1071],{},"amount",[32,1073,729],{}," sums those amounts to ",[32,1076,1077],{},"300",". Each method returns a new array (or value), which is exactly what makes chaining them together work.",[14,1080,1081,1085,1140,1170],{"language":16},[18,1082,1084],{"id":1083},"q7-what-does-this-log","Q7. What does this log?",[23,1086,1087],{"language":16},[26,1088,1090],{"className":28,"code":1089,"language":16,"meta":30,"style":30},"const add = a => b => a + b;\nconsole.log(add(3)(4));\n",[32,1091,1092,1118],{"__ignoreMap":30},[35,1093,1094,1096,1099,1101,1104,1106,1109,1111,1113,1115],{"class":37,"line":38},[35,1095,97],{"class":41},[35,1097,1098],{"class":45}," add",[35,1100,104],{"class":41},[35,1102,1103],{"class":53}," a",[35,1105,126],{"class":41},[35,1107,1108],{"class":53}," b",[35,1110,126],{"class":41},[35,1112,974],{"class":49},[35,1114,752],{"class":41},[35,1116,1117],{"class":49}," b;\n",[35,1119,1120,1122,1124,1126,1129,1131,1133,1136,1138],{"class":37,"line":66},[35,1121,144],{"class":49},[35,1123,147],{"class":45},[35,1125,50],{"class":49},[35,1127,1128],{"class":45},"add",[35,1130,50],{"class":49},[35,1132,577],{"class":100},[35,1134,1135],{"class":49},")(",[35,1137,582],{"class":100},[35,1139,352],{"class":49},[152,1141,1143,1149,1158,1164],{"className":1142},[155],[157,1144,1146,1148],{"className":1145},[160],[162,1147],{"disabled":90,"type":164}," 7",[157,1150,1152,182,1154,1157],{"className":1151},[160],[162,1153],{"disabled":90,"type":164},[32,1155,1156],{},"add(3)"," isn't callable",[157,1159,1161,1163],{"className":1160},[160],[162,1162],{"disabled":90,"type":164}," \"34\" (string concatenation)",[157,1165,1167,1169],{"className":1166},[160],[162,1168],{"disabled":90,"type":164}," undefined",[195,1171,1172,1174,1179],{},[198,1173,200],{},[123,1175,1176,1178],{},[204,1177,206],{}," A — 7",[123,1180,1181,1183,1184,1187,1188,1190,1191,1194,1195,407,1197,1199,1200,414,1202,1205,1206,229,1208,1210],{},[204,1182,214],{}," This is basic ",[204,1185,1186],{},"currying",": ",[32,1189,1156],{}," returns a new arrow function ",[32,1192,1193],{},"b => 3 + b"," (with ",[32,1196,962],{},[32,1198,577],{}," via closure), and calling that with ",[32,1201,582],{},[32,1203,1204],{},"3 + 4 = 7",". Both ",[32,1207,962],{},[32,1209,967],{}," are numbers, so there's no string coercion involved.",[14,1212,1213,1217,1253,1284],{"language":16},[18,1214,1216],{"id":1215},"q8-what-does-this-famously-log","Q8. What does this famously log?",[23,1218,1219],{"language":16},[26,1220,1222],{"className":28,"code":1221,"language":16,"meta":30,"style":30},"console.log(['1', '2', '3'].map(parseInt));\n",[32,1223,1224],{"__ignoreMap":30},[35,1225,1226,1228,1230,1232,1235,1237,1240,1242,1245,1248,1250],{"class":37,"line":38},[35,1227,144],{"class":49},[35,1229,147],{"class":45},[35,1231,109],{"class":49},[35,1233,1234],{"class":446},"'1'",[35,1236,57],{"class":49},[35,1238,1239],{"class":446},"'2'",[35,1241,57],{"class":49},[35,1243,1244],{"class":446},"'3'",[35,1246,1247],{"class":49},"].",[35,1249,75],{"class":45},[35,1251,1252],{"class":49},"(parseInt));\n",[152,1254,1256,1264,1271,1279],{"className":1255},[155],[157,1257,1259,165,1261],{"className":1258},[160],[162,1260],{"disabled":90,"type":164},[35,1262,1263],{},"1, NaN, NaN",[157,1265,1267,165,1269],{"className":1266},[160],[162,1268],{"disabled":90,"type":164},[35,1270,635],{},[157,1272,1274,165,1276],{"className":1273},[160],[162,1275],{"disabled":90,"type":164},[35,1277,1278],{},"1, 2, NaN",[157,1280,1282,512],{"className":1281},[160],[162,1283],{"disabled":90,"type":164},[195,1285,1286,1288,1294],{},[198,1287,200],{},[123,1289,1290,207,1292],{},[204,1291,206],{},[35,1293,1263],{},[123,1295,1296,165,1298,1300,1301,1303,1304,1307,1308,1311,1312,1315,1316,1319,1320,1322,1323,1065,1325,1319,1328,1330,1331,1334,1335,1338,1339,1341,1342,1344,1345,1348,1349,1352],{},[204,1297,214],{},[204,1299,244],{}," this is one of JavaScript's most famous \"wat\" moments. ",[32,1302,75],{}," invokes its callback with ",[204,1305,1306],{},"three"," arguments — ",[32,1309,1310],{},"(element, index, array)"," — and ",[32,1313,1314],{},"parseInt(string, radix)"," treats that second argument as a radix. So it actually runs ",[32,1317,1318],{},"parseInt('1', 0, [...])"," (radix ",[32,1321,758],{}," means \"auto-detect,\" which defaults to base 10, giving ",[32,1324,568],{},[32,1326,1327],{},"parseInt('2', 1, [...])",[32,1329,568],{}," is invalid, giving ",[32,1332,1333],{},"NaN","), and ",[32,1336,1337],{},"parseInt('3', 2, [...])"," (base 2 can't contain the digit ",[32,1340,1244],{},", giving ",[32,1343,1333],{},"). The fix is ",[32,1346,1347],{},"['1','2','3'].map(s => parseInt(s, 10))"," or ",[32,1350,1351],{},".map(Number)",".",[14,1354,1355,1359,1396,1431],{"language":16},[18,1356,1358],{"id":1357},"q9-what-happens-here","Q9. What happens here?",[23,1360,1361],{"language":16},[26,1362,1364],{"className":28,"code":1363,"language":16,"meta":30,"style":30},"console.log([].reduce((a, b) => a + b));\n",[32,1365,1366],{"__ignoreMap":30},[35,1367,1368,1370,1372,1375,1377,1379,1381,1383,1385,1387,1389,1391,1393],{"class":37,"line":38},[35,1369,144],{"class":49},[35,1371,147],{"class":45},[35,1373,1374],{"class":49},"([].",[35,1376,729],{"class":45},[35,1378,732],{"class":49},[35,1380,962],{"class":53},[35,1382,57],{"class":49},[35,1384,967],{"class":53},[35,1386,743],{"class":49},[35,1388,746],{"class":41},[35,1390,974],{"class":49},[35,1392,752],{"class":41},[35,1394,1395],{"class":49}," b));\n",[152,1397,1399,1408,1416,1424],{"className":1398},[155],[157,1400,1402,1404,1405],{"className":1401},[160],[162,1403],{"disabled":90,"type":164}," Throws ",[32,1406,1407],{},"TypeError: Reduce of empty array with no initial value",[157,1409,1411,1413,1414],{"className":1410},[160],[162,1412],{"disabled":90,"type":164}," Logs ",[32,1415,758],{},[157,1417,1419,1413,1421],{"className":1418},[160],[162,1420],{"disabled":90,"type":164},[32,1422,1423],{},"undefined",[157,1425,1427,1413,1429],{"className":1426},[160],[162,1428],{"disabled":90,"type":164},[32,1430,1333],{},[195,1432,1433,1435,1442],{},[198,1434,200],{},[123,1436,1437,1439,1440],{},[204,1438,206],{}," A — Throws ",[32,1441,1407],{},[123,1443,1444,1446,1447,1449,1450,1348,1452,1454],{},[204,1445,214],{}," Without an initial value, ",[32,1448,729],{}," tries to use the array's first element as the starting accumulator — but an empty array has no first element, and there's nothing meaningful to return, so it throws instead of silently producing ",[32,1451,758],{},[32,1453,1423],{},". The fix (and the general best practice — see Q10) is to always supply an explicit initial value.",[14,1456,1457,1461,1500,1525],{"language":16},[18,1458,1460],{"id":1459},"q10-what-does-this-log","Q10. What does this log?",[23,1462,1463],{"language":16},[26,1464,1466],{"className":28,"code":1465,"language":16,"meta":30,"style":30},"console.log([].reduce((a, b) => a + b, 100));\n",[32,1467,1468],{"__ignoreMap":30},[35,1469,1470,1472,1474,1476,1478,1480,1482,1484,1486,1488,1490,1492,1494,1496,1498],{"class":37,"line":38},[35,1471,144],{"class":49},[35,1473,147],{"class":45},[35,1475,1374],{"class":49},[35,1477,729],{"class":45},[35,1479,732],{"class":49},[35,1481,962],{"class":53},[35,1483,57],{"class":49},[35,1485,967],{"class":53},[35,1487,743],{"class":49},[35,1489,746],{"class":41},[35,1491,974],{"class":49},[35,1493,752],{"class":41},[35,1495,979],{"class":49},[35,1497,112],{"class":100},[35,1499,352],{"class":49},[152,1501,1503,1509,1515,1520],{"className":1502},[155],[157,1504,1506,1508],{"className":1505},[160],[162,1507],{"disabled":90,"type":164}," 100",[157,1510,1512,1514],{"className":1511},[160],[162,1513],{"disabled":90,"type":164}," Throws a TypeError, same as with no initial value",[157,1516,1518,376],{"className":1517},[160],[162,1519],{"disabled":90,"type":164},[157,1521,1523,1169],{"className":1522},[160],[162,1524],{"disabled":90,"type":164},[195,1526,1527,1529,1534],{},[198,1528,200],{},[123,1530,1531,1533],{},[204,1532,206],{}," A — 100",[123,1535,1536,1538,1539,1541,1542,1545],{},[204,1537,214],{}," With an initial value supplied, ",[32,1540,729],{}," on an empty array simply returns that initial value ",[204,1543,1544],{},"without ever invoking the callback"," — there are no elements to combine it with. This is the safe, predictable behavior that Q9's version lacks, and it's why always passing an initial value is the recommended default.",[14,1547,1548,1552,1702,1730],{"language":16},[18,1549,1551],{"id":1550},"q11-what-does-this-log","Q11. What does this log?",[23,1553,1554],{"language":16},[26,1555,1557],{"className":28,"code":1556,"language":16,"meta":30,"style":30},"function findFirstEven(arr) {\n  let result;\n  arr.forEach(n => {\n    if (n % 2 === 0) {\n      result = n;\n      return;\n    }\n  });\n  return result;\n}\n\nconsole.log(findFirstEven([1, 3, 5, 4, 6, 8]));\n",[32,1558,1559,1573,1581,1598,1619,1630,1638,1643,1648,1654,1658,1662],{"__ignoreMap":30},[35,1560,1561,1563,1566,1568,1571],{"class":37,"line":38},[35,1562,42],{"class":41},[35,1564,1565],{"class":45}," findFirstEven",[35,1567,50],{"class":49},[35,1569,1570],{"class":53},"arr",[35,1572,63],{"class":49},[35,1574,1575,1578],{"class":37,"line":66},[35,1576,1577],{"class":41},"  let",[35,1579,1580],{"class":49}," result;\n",[35,1582,1583,1586,1589,1591,1593,1595],{"class":37,"line":81},[35,1584,1585],{"class":49},"  arr.",[35,1587,1588],{"class":45},"forEach",[35,1590,50],{"class":49},[35,1592,285],{"class":53},[35,1594,126],{"class":41},[35,1596,1597],{"class":49}," {\n",[35,1599,1600,1603,1606,1609,1612,1615,1617],{"class":37,"line":87},[35,1601,1602],{"class":41},"    if",[35,1604,1605],{"class":49}," (n ",[35,1607,1608],{"class":41},"%",[35,1610,1611],{"class":100}," 2",[35,1613,1614],{"class":41}," ===",[35,1616,775],{"class":100},[35,1618,63],{"class":49},[35,1620,1621,1624,1627],{"class":37,"line":94},[35,1622,1623],{"class":49},"      result ",[35,1625,1626],{"class":41},"=",[35,1628,1629],{"class":49}," n;\n",[35,1631,1632,1635],{"class":37,"line":141},[35,1633,1634],{"class":41},"      return",[35,1636,1637],{"class":49},";\n",[35,1639,1640],{"class":37,"line":316},[35,1641,1642],{"class":49},"    }\n",[35,1644,1645],{"class":37,"line":335},[35,1646,1647],{"class":49},"  });\n",[35,1649,1650,1652],{"class":37,"line":937},[35,1651,69],{"class":41},[35,1653,1580],{"class":49},[35,1655,1656],{"class":37,"line":953},[35,1657,84],{"class":49},[35,1659,1660],{"class":37,"line":986},[35,1661,91],{"emptyLinePlaceholder":90},[35,1663,1664,1666,1668,1670,1673,1675,1677,1679,1681,1683,1685,1687,1689,1691,1694,1696,1699],{"class":37,"line":991},[35,1665,144],{"class":49},[35,1667,147],{"class":45},[35,1669,50],{"class":49},[35,1671,1672],{"class":45},"findFirstEven",[35,1674,109],{"class":49},[35,1676,568],{"class":100},[35,1678,57],{"class":49},[35,1680,577],{"class":100},[35,1682,57],{"class":49},[35,1684,349],{"class":100},[35,1686,57],{"class":49},[35,1688,582],{"class":100},[35,1690,57],{"class":49},[35,1692,1693],{"class":100},"6",[35,1695,57],{"class":49},[35,1697,1698],{"class":100},"8",[35,1700,1701],{"class":49},"]));\n",[152,1703,1705,1711,1717,1722],{"className":1704},[155],[157,1706,1708,1710],{"className":1707},[160],[162,1709],{"disabled":90,"type":164}," 8",[157,1712,1714,1716],{"className":1713},[160],[162,1715],{"disabled":90,"type":164}," 4",[157,1718,1720,1169],{"className":1719},[160],[162,1721],{"disabled":90,"type":164},[157,1723,1725,165,1727],{"className":1724},[160],[162,1726],{"disabled":90,"type":164},[35,1728,1729],{},"4, 6, 8",[195,1731,1732,1734,1739],{},[198,1733,200],{},[123,1735,1736,1738],{},[204,1737,206],{}," A — 8",[123,1740,1741,165,1743,1745,1746,1749,1750,1752,1753,1756,1757,1759,1760,1763,1764,1766,1767,1766,1769,1771,1772,1776,1777,1780,1781,1784,1785,1352],{},[204,1742,214],{},[204,1744,244],{}," the ",[32,1747,1748],{},"return"," inside the ",[32,1751,1588],{}," callback only exits that single invocation of the callback — it does ",[204,1754,1755],{},"not"," break out of the loop, because ",[32,1758,1588],{}," provides no mechanism for early termination at all. So the callback keeps running for every element, and ",[32,1761,1762],{},"result"," gets overwritten each time an even number is found (",[32,1765,582],{},", then ",[32,1768,1693],{},[32,1770,1698],{},"), ending on the ",[1773,1774,1775],"em",{},"last"," even number rather than the first. The correct fix for \"stop at the first match\" is ",[32,1778,1779],{},"arr.find(n => n % 2 === 0)",", or a ",[32,1782,1783],{},"for...of"," loop with a real ",[32,1786,1787],{},"break",[14,1789,1790,1794,1844,1880],{"language":16},[18,1791,1793],{"id":1792},"q12-what-does-this-log","Q12. What does this log?",[23,1795,1796],{"language":16},[26,1797,1799],{"className":28,"code":1798,"language":16,"meta":30,"style":30},"const scores = [10, 1, 2, 21];\nconsole.log(scores.sort());\n",[32,1800,1801,1829],{"__ignoreMap":30},[35,1802,1803,1805,1808,1810,1812,1814,1816,1818,1820,1822,1824,1827],{"class":37,"line":38},[35,1804,97],{"class":41},[35,1806,1807],{"class":100}," scores",[35,1809,104],{"class":41},[35,1811,443],{"class":49},[35,1813,704],{"class":100},[35,1815,57],{"class":49},[35,1817,568],{"class":100},[35,1819,57],{"class":49},[35,1821,330],{"class":100},[35,1823,57],{"class":49},[35,1825,1826],{"class":100},"21",[35,1828,455],{"class":49},[35,1830,1831,1833,1835,1838,1841],{"class":37,"line":66},[35,1832,144],{"class":49},[35,1834,147],{"class":45},[35,1836,1837],{"class":49},"(scores.",[35,1839,1840],{"class":45},"sort",[35,1842,1843],{"class":49},"());\n",[152,1845,1847,1855,1863,1871],{"className":1846},[155],[157,1848,1850,165,1852],{"className":1849},[160],[162,1851],{"disabled":90,"type":164},[35,1853,1854],{},"1, 10, 2, 21",[157,1856,1858,165,1860],{"className":1857},[160],[162,1859],{"disabled":90,"type":164},[35,1861,1862],{},"1, 2, 10, 21",[157,1864,1866,165,1868],{"className":1865},[160],[162,1867],{"disabled":90,"type":164},[35,1869,1870],{},"21, 10, 2, 1",[157,1872,1874,165,1876,1879],{"className":1873},[160],[162,1875],{"disabled":90,"type":164},[35,1877,1878],{},"10, 1, 2, 21"," (unchanged)",[195,1881,1882,1884,1890],{},[198,1883,200],{},[123,1885,1886,207,1888],{},[204,1887,206],{},[35,1889,1854],{},[123,1891,1892,165,1894,165,1896,1899,1900,1903,1904,1907,1908,1910,1911,1914,1915,1918,1919,1352],{},[204,1893,214],{},[204,1895,244],{},[32,1897,1898],{},"Array.prototype.sort()"," with no comparator converts every element to a ",[204,1901,1902],{},"string"," and compares them lexicographically (by UTF-16 code unit), not numerically. ",[32,1905,1906],{},"'10'"," sorts before ",[32,1909,1239],{}," because ",[32,1912,1913],{},"'1' \u003C '2'"," as characters, even though ",[32,1916,1917],{},"10 > 2"," numerically. The fix is always to pass an explicit comparator for numbers: ",[32,1920,1921],{},"scores.sort((a, b) => a - b)",[14,1923,1924,1935,1967,2023],{"language":16},[18,1925,1927,1928,1930,1931,1934],{"id":1926},"q13-why-does-mapnumber-behave-correctly-while-mapparseint-q8-does-not","Q13. Why does ",[32,1929,1351],{}," behave correctly while ",[32,1932,1933],{},".map(parseInt)"," (Q8) does not?",[23,1936,1937],{"language":16},[26,1938,1940],{"className":28,"code":1939,"language":16,"meta":30,"style":30},"console.log(['1', '2', '3'].map(Number));\n",[32,1941,1942],{"__ignoreMap":30},[35,1943,1944,1946,1948,1950,1952,1954,1956,1958,1960,1962,1964],{"class":37,"line":38},[35,1945,144],{"class":49},[35,1947,147],{"class":45},[35,1949,109],{"class":49},[35,1951,1234],{"class":446},[35,1953,57],{"class":49},[35,1955,1239],{"class":446},[35,1957,57],{"class":49},[35,1959,1244],{"class":446},[35,1961,1247],{"class":49},[35,1963,75],{"class":45},[35,1965,1966],{"class":49},"(Number));\n",[152,1968,1970,1989,2001,2015],{"className":1969},[155],[157,1971,1973,165,1975,1978,1979,237,1982,1985,1986,1988],{"className":1972},[160],[162,1974],{"disabled":90,"type":164},[32,1976,1977],{},"Number(value)"," only ever looks at its first argument, so the extra ",[32,1980,1981],{},"index",[32,1983,1984],{},"array"," arguments ",[32,1987,75],{}," passes are harmless",[157,1990,1992,165,1994,1996,1997,2000],{"className":1991},[160],[162,1993],{"disabled":90,"type":164},[32,1995,75],{}," special-cases ",[32,1998,1999],{},"Number"," and only passes it one argument",[157,2002,2004,165,2006,229,2008,2011,2012],{"className":2003},[160],[162,2005],{"disabled":90,"type":164},[32,2007,1999],{},[32,2009,2010],{},"parseInt"," behave identically, so this also produces ",[32,2013,2014],{},"[1, NaN, NaN]",[157,2016,2018,165,2020,2022],{"className":2017},[160],[162,2019],{"disabled":90,"type":164},[32,2021,1999],{}," mutates the original array, so this is actually a different kind of bug",[195,2024,2025,2027,2039],{},[198,2026,200],{},[123,2028,2029,207,2031,1978,2033,237,2035,1985,2037,1988],{},[204,2030,206],{},[32,2032,1977],{},[32,2034,1981],{},[32,2036,1984],{},[32,2038,75],{},[123,2040,2041,165,2043,165,2046,2048,2049,2052,2053,2056,2057,2060,2061,2064,2065,401,2068,2070,2071,2074,2075,2077],{},[204,2042,214],{},[204,2044,2045],{},"Idiom:",[32,2047,75],{}," always calls its callback as ",[32,2050,2051],{},"callback(element, index, array)"," regardless of which function you pass — the difference is entirely in how the callback ",[1773,2054,2055],{},"reacts"," to those extra arguments. ",[32,2058,2059],{},"Number(v)"," ignores anything beyond the first parameter, so ",[32,2062,2063],{},"[1,2,3].map(Number)"," is safe and gives ",[32,2066,2067],{},"[1, 2, 3]",[32,2069,1314],{},", uniquely among common conversion functions, ",[1773,2072,2073],{},"does"," use its second parameter, which is what turns ",[32,2076,75],{},"'s index argument into an accidental radix in Q8.",[14,2079,2080,2084,2286,2316],{"language":16},[18,2081,2083],{"id":2082},"q14-what-happens-here","Q14. What happens here?",[23,2085,2086],{"language":16},[26,2087,2089],{"className":28,"code":2088,"language":16,"meta":30,"style":30},"function curry(fn) {\n  return function curried(...args) {\n    if (args.length >= fn.length) return fn(...args);\n    return (...more) => curried(...args, ...more);\n  };\n}\n\nfunction greet(greeting, name = 'friend') {\n  return `${greeting}, ${name}!`;\n}\n\nconst curriedGreet = curry(greet);\nconsole.log(curriedGreet('Hi')('Sam'));\n",[32,2090,2091,2105,2124,2156,2185,2189,2193,2197,2221,2240,2244,2248,2262],{"__ignoreMap":30},[35,2092,2093,2095,2098,2100,2103],{"class":37,"line":38},[35,2094,42],{"class":41},[35,2096,2097],{"class":45}," curry",[35,2099,50],{"class":49},[35,2101,2102],{"class":53},"fn",[35,2104,63],{"class":49},[35,2106,2107,2109,2111,2114,2116,2119,2122],{"class":37,"line":66},[35,2108,69],{"class":41},[35,2110,279],{"class":41},[35,2112,2113],{"class":45}," curried",[35,2115,50],{"class":49},[35,2117,2118],{"class":41},"...",[35,2120,2121],{"class":53},"args",[35,2123,63],{"class":49},[35,2125,2126,2128,2131,2134,2137,2140,2142,2144,2146,2149,2151,2153],{"class":37,"line":81},[35,2127,1602],{"class":41},[35,2129,2130],{"class":49}," (args.",[35,2132,2133],{"class":100},"length",[35,2135,2136],{"class":41}," >=",[35,2138,2139],{"class":49}," fn.",[35,2141,2133],{"class":100},[35,2143,743],{"class":49},[35,2145,1748],{"class":41},[35,2147,2148],{"class":45}," fn",[35,2150,50],{"class":49},[35,2152,2118],{"class":41},[35,2154,2155],{"class":49},"args);\n",[35,2157,2158,2160,2162,2164,2167,2169,2171,2173,2175,2177,2180,2182],{"class":37,"line":87},[35,2159,292],{"class":41},[35,2161,282],{"class":49},[35,2163,2118],{"class":41},[35,2165,2166],{"class":53},"more",[35,2168,743],{"class":49},[35,2170,746],{"class":41},[35,2172,2113],{"class":45},[35,2174,50],{"class":49},[35,2176,2118],{"class":41},[35,2178,2179],{"class":49},"args, ",[35,2181,2118],{"class":41},[35,2183,2184],{"class":49},"more);\n",[35,2186,2187],{"class":37,"line":94},[35,2188,305],{"class":49},[35,2190,2191],{"class":37,"line":141},[35,2192,84],{"class":49},[35,2194,2195],{"class":37,"line":316},[35,2196,91],{"emptyLinePlaceholder":90},[35,2198,2199,2201,2204,2206,2209,2211,2214,2216,2219],{"class":37,"line":335},[35,2200,42],{"class":41},[35,2202,2203],{"class":45}," greet",[35,2205,50],{"class":49},[35,2207,2208],{"class":53},"greeting",[35,2210,57],{"class":49},[35,2212,2213],{"class":53},"name",[35,2215,104],{"class":41},[35,2217,2218],{"class":446}," 'friend'",[35,2220,63],{"class":49},[35,2222,2223,2225,2228,2230,2233,2235,2238],{"class":37,"line":937},[35,2224,69],{"class":41},[35,2226,2227],{"class":446}," `${",[35,2229,2208],{"class":49},[35,2231,2232],{"class":446},"}, ${",[35,2234,2213],{"class":49},[35,2236,2237],{"class":446},"}!`",[35,2239,1637],{"class":49},[35,2241,2242],{"class":37,"line":953},[35,2243,84],{"class":49},[35,2245,2246],{"class":37,"line":986},[35,2247,91],{"emptyLinePlaceholder":90},[35,2249,2250,2252,2255,2257,2259],{"class":37,"line":991},[35,2251,97],{"class":41},[35,2253,2254],{"class":100}," curriedGreet",[35,2256,104],{"class":41},[35,2258,2097],{"class":45},[35,2260,2261],{"class":49},"(greet);\n",[35,2263,2265,2267,2269,2271,2274,2276,2279,2281,2284],{"class":37,"line":2264},13,[35,2266,144],{"class":49},[35,2268,147],{"class":45},[35,2270,50],{"class":49},[35,2272,2273],{"class":45},"curriedGreet",[35,2275,50],{"class":49},[35,2277,2278],{"class":446},"'Hi'",[35,2280,1135],{"class":49},[35,2282,2283],{"class":446},"'Sam'",[35,2285,352],{"class":49},[152,2287,2289,2298,2304,2310],{"className":2288},[155],[157,2290,2292,182,2294,2297],{"className":2291},[160],[162,2293],{"disabled":90,"type":164},[32,2295,2296],{},"curriedGreet('Hi')"," returns a string, and strings aren't callable",[157,2299,2301,2303],{"className":2300},[160],[162,2302],{"disabled":90,"type":164}," \"Hi, Sam!\"",[157,2305,2307,2309],{"className":2306},[160],[162,2308],{"disabled":90,"type":164}," \"Hi, friend!\"",[157,2311,2313,2315],{"className":2312},[160],[162,2314],{"disabled":90,"type":164}," \"Hi, undefined!\"",[195,2317,2318,2320,2327],{},[198,2319,200],{},[123,2321,2322,2324,2325,2297],{},[204,2323,206],{}," A — Throws a TypeError because ",[32,2326,2296],{},[123,2328,2329,165,2331,165,2333,2336,2337,2340,2341,2344,2345,2347,2348,2350,2351,2354,2355,2358,2359,2362,2363,2365,2366,2369,2370,2373,2374,2377,2378,2381],{},[204,2330,214],{},[204,2332,244],{},[32,2334,2335],{},"Function.prototype.length"," only counts parameters ",[204,2338,2339],{},"before"," the first one with a default value (or a rest parameter) — so ",[32,2342,2343],{},"greet.length"," is ",[32,2346,568],{},", not ",[32,2349,330],{},", even though ",[32,2352,2353],{},"greet"," accepts two arguments. ",[32,2356,2357],{},"curry","'s arity check (",[32,2360,2361],{},"args.length >= fn.length",") is satisfied the moment ",[32,2364,2296],{}," is called with just one argument, so it immediately invokes ",[32,2367,2368],{},"greet('Hi')",", producing the string ",[32,2371,2372],{},"\"Hi, friend!\""," — not another curried function. Calling that string with ",[32,2375,2376],{},"('Sam')"," then throws, because a string isn't a function. This is why generic ",[32,2379,2380],{},"fn.length","-based curry helpers are fragile against default and rest parameters.",[14,2383,2384,2388,2490,2525],{"language":16},[18,2385,2387],{"id":2386},"q15-which-style-is-generally-preferred-and-why","Q15. Which style is generally preferred, and why?",[23,2389,2390],{"language":16},[26,2391,2393],{"className":28,"code":2392,"language":16,"meta":30,"style":30},"\u002F\u002F Style A\nlet result = [];\nitems.forEach(item => {\n  if (item.active) result.push(transform(item));\n});\n\n\u002F\u002F Style B\nconst result2 = items.filter(item => item.active).map(transform);\n",[32,2394,2395,2401,2414,2429,2448,2453,2457,2462],{"__ignoreMap":30},[35,2396,2397],{"class":37,"line":38},[35,2398,2400],{"class":2399},"sdCPZ","\u002F\u002F Style A\n",[35,2402,2403,2406,2409,2411],{"class":37,"line":66},[35,2404,2405],{"class":41},"let",[35,2407,2408],{"class":49}," result ",[35,2410,1626],{"class":41},[35,2412,2413],{"class":49}," [];\n",[35,2415,2416,2419,2421,2423,2425,2427],{"class":37,"line":81},[35,2417,2418],{"class":49},"items.",[35,2420,1588],{"class":45},[35,2422,50],{"class":49},[35,2424,740],{"class":53},[35,2426,126],{"class":41},[35,2428,1597],{"class":49},[35,2430,2431,2434,2437,2440,2442,2445],{"class":37,"line":87},[35,2432,2433],{"class":41},"  if",[35,2435,2436],{"class":49}," (item.active) result.",[35,2438,2439],{"class":45},"push",[35,2441,50],{"class":49},[35,2443,2444],{"class":45},"transform",[35,2446,2447],{"class":49},"(item));\n",[35,2449,2450],{"class":37,"line":94},[35,2451,2452],{"class":49},"});\n",[35,2454,2455],{"class":37,"line":141},[35,2456,91],{"emptyLinePlaceholder":90},[35,2458,2459],{"class":37,"line":316},[35,2460,2461],{"class":2399},"\u002F\u002F Style B\n",[35,2463,2464,2466,2469,2471,2474,2476,2478,2480,2482,2485,2487],{"class":37,"line":335},[35,2465,97],{"class":41},[35,2467,2468],{"class":100}," result2",[35,2470,104],{"class":41},[35,2472,2473],{"class":49}," items.",[35,2475,600],{"class":45},[35,2477,50],{"class":49},[35,2479,740],{"class":53},[35,2481,126],{"class":41},[35,2483,2484],{"class":49}," item.active).",[35,2486,75],{"class":45},[35,2488,2489],{"class":49},"(transform);\n",[152,2491,2493,2499,2508,2514],{"className":2492},[155],[157,2494,2496,2498],{"className":2495},[160],[162,2497],{"disabled":90,"type":164}," Style B — it's declarative, avoids relying on an external mutable accumulator, and makes the transformation's intent explicit",[157,2500,2502,2504,2505,2507],{"className":2501},[160],[162,2503],{"disabled":90,"type":164}," Style A — ",[32,2506,1588],{}," is always meaningfully faster, so it should be preferred",[157,2509,2511,2513],{"className":2510},[160],[162,2512],{"disabled":90,"type":164}," They're equally idiomatic; there's no practical difference in real codebases",[157,2515,2517,2519,2520,2522,2523],{"className":2516},[160],[162,2518],{"disabled":90,"type":164}," Style B is invalid — you can't chain ",[32,2521,1028],{}," directly into ",[32,2524,1031],{},[195,2526,2527,2529,2534],{},[198,2528,200],{},[123,2530,2531,2533],{},[204,2532,206],{}," A — Style B — it's declarative, avoids relying on an external mutable accumulator, and makes the transformation's intent explicit",[123,2535,2536,165,2538,2540,2541,2544,2545,2547,2548,2550,2551,2553],{},[204,2537,214],{},[204,2539,2045],{}," Style A depends on an externally-declared ",[32,2542,2543],{},"let result = []"," that the callback mutates as a side effect — easy to accidentally push twice, forget to initialize, or shadow in a refactor. Style B expresses the same operation as a pipeline of pure transformations with no external mutable state to get wrong. (For very large arrays where the double pass — one for ",[32,2546,600],{},", one for ",[32,2549,75],{}," — actually matters, a single ",[32,2552,729],{}," can combine both into one pass, but for typical sizes, readability wins and the filter\u002Fmap chain is the standard idiom.)",[14,2555,2556,2560,2642,2691],{"language":16},[18,2557,2559],{"id":2558},"q16-whats-the-problem-with-this-code","Q16. What's the problem with this code?",[23,2561,2562],{"language":16},[26,2563,2565],{"className":28,"code":2564,"language":16,"meta":30,"style":30},"const total = orders\n  .map(o => {\n    o.processed = true;\n    return o.amount;\n  })\n  .reduce((a, b) => a + b, 0);\n",[32,2566,2567,2577,2591,2602,2609,2614],{"__ignoreMap":30},[35,2568,2569,2571,2573,2575],{"class":37,"line":38},[35,2570,97],{"class":41},[35,2572,903],{"class":100},[35,2574,104],{"class":41},[35,2576,908],{"class":49},[35,2578,2579,2581,2583,2585,2587,2589],{"class":37,"line":66},[35,2580,913],{"class":49},[35,2582,75],{"class":45},[35,2584,50],{"class":49},[35,2586,920],{"class":53},[35,2588,126],{"class":41},[35,2590,1597],{"class":49},[35,2592,2593,2596,2598,2600],{"class":37,"line":81},[35,2594,2595],{"class":49},"    o.processed ",[35,2597,1626],{"class":41},[35,2599,641],{"class":100},[35,2601,1637],{"class":49},[35,2603,2604,2606],{"class":37,"line":87},[35,2605,292],{"class":41},[35,2607,2608],{"class":49}," o.amount;\n",[35,2610,2611],{"class":37,"line":94},[35,2612,2613],{"class":49},"  })\n",[35,2615,2616,2618,2620,2622,2624,2626,2628,2630,2632,2634,2636,2638,2640],{"class":37,"line":141},[35,2617,913],{"class":49},[35,2619,729],{"class":45},[35,2621,732],{"class":49},[35,2623,962],{"class":53},[35,2625,57],{"class":49},[35,2627,967],{"class":53},[35,2629,743],{"class":49},[35,2631,746],{"class":41},[35,2633,974],{"class":49},[35,2635,752],{"class":41},[35,2637,979],{"class":49},[35,2639,758],{"class":100},[35,2641,138],{"class":49},[152,2643,2645,2661,2670,2682],{"className":2644},[155],[157,2646,2648,2650,2651,2653,2654,2657,2658,2660],{"className":2647},[160],[162,2649],{"disabled":90,"type":164}," The ",[32,2652,75],{}," callback has a hidden side effect — mutating the original ",[32,2655,2656],{},"orders"," objects — when ",[32,2659,75],{}," is expected to just transform and return values",[157,2662,2664,2666,2667,2669],{"className":2663},[160],[162,2665],{"disabled":90,"type":164}," This throws a TypeError because ",[32,2668,75],{}," callbacks can't have a function body with multiple statements",[157,2671,2673,165,2675,2677,2678,2681],{"className":2672},[160],[162,2674],{"disabled":90,"type":164},[32,2676,75],{}," automatically deep-clones each element, so ",[32,2679,2680],{},"o.processed = true"," has no effect on the original array",[157,2683,2685,2687,2688,2690],{"className":2684},[160],[162,2686],{"disabled":90,"type":164}," There's no problem; mutating inside ",[32,2689,75],{}," is the standard way to flag processed items",[195,2692,2693,2695,2706],{},[198,2694,200],{},[123,2696,2697,2699,2700,2653,2702,2657,2704,2660],{},[204,2698,206],{}," A — The ",[32,2701,75],{},[32,2703,2656],{},[32,2705,75],{},[123,2707,2708,165,2710,165,2712,2714,2715,2718,2719,2721,2722,2724,2725,237,2727,2729,2730,2732],{},[204,2709,214],{},[204,2711,2045],{},[32,2713,75],{},"'s contract is \"produce a new value per element,\" not \"do something to the element.\" Mutating ",[32,2716,2717],{},"o.processed"," here is easy to miss when reading the code (you have to read past the ",[32,2720,1748],{}," to notice it), and it silently changes the original ",[32,2723,2656],{}," array\u002Fobjects, which can cause bugs if that same array is read elsewhere, memoized, or the pipeline is accidentally run twice. Best practice is to keep ",[32,2726,75],{},[32,2728,600],{}," callbacks pure and do side-effecting work in a separate, clearly-named step (e.g. a ",[32,2731,1588],{}," or explicit loop).",[14,2734,2735,2739,2824,2866],{"language":16},[18,2736,2738],{"id":2737},"q17-which-is-the-better-choice-for-finding-a-single-matching-user-in-a-large-array-and-why","Q17. Which is the better choice for finding a single matching user in a large array, and why?",[23,2740,2741],{"language":16},[26,2742,2744],{"className":28,"code":2743,"language":16,"meta":30,"style":30},"\u002F\u002F Option A\nconst admin = users.filter(u => u.role === 'admin')[0];\n\n\u002F\u002F Option B\nconst admin2 = users.find(u => u.role === 'admin');\n",[32,2745,2746,2751,2787,2791,2796],{"__ignoreMap":30},[35,2747,2748],{"class":37,"line":38},[35,2749,2750],{"class":2399},"\u002F\u002F Option A\n",[35,2752,2753,2755,2758,2760,2763,2765,2767,2770,2772,2775,2777,2780,2783,2785],{"class":37,"line":66},[35,2754,97],{"class":41},[35,2756,2757],{"class":100}," admin",[35,2759,104],{"class":41},[35,2761,2762],{"class":49}," users.",[35,2764,600],{"class":45},[35,2766,50],{"class":49},[35,2768,2769],{"class":53},"u",[35,2771,126],{"class":41},[35,2773,2774],{"class":49}," u.role ",[35,2776,928],{"class":41},[35,2778,2779],{"class":446}," 'admin'",[35,2781,2782],{"class":49},")[",[35,2784,758],{"class":100},[35,2786,455],{"class":49},[35,2788,2789],{"class":37,"line":81},[35,2790,91],{"emptyLinePlaceholder":90},[35,2792,2793],{"class":37,"line":87},[35,2794,2795],{"class":2399},"\u002F\u002F Option B\n",[35,2797,2798,2800,2803,2805,2807,2810,2812,2814,2816,2818,2820,2822],{"class":37,"line":94},[35,2799,97],{"class":41},[35,2801,2802],{"class":100}," admin2",[35,2804,104],{"class":41},[35,2806,2762],{"class":49},[35,2808,2809],{"class":45},"find",[35,2811,50],{"class":49},[35,2813,2769],{"class":53},[35,2815,126],{"class":41},[35,2817,2774],{"class":49},[35,2819,928],{"class":41},[35,2821,2779],{"class":446},[35,2823,138],{"class":49},[152,2825,2827,2841,2850,2856],{"className":2826},[155],[157,2828,2830,2832,2833,2835,2836,2838,2839],{"className":2829},[160],[162,2831],{"disabled":90,"type":164}," Option B — ",[32,2834,2809],{}," stops as soon as it finds a match, while ",[32,2837,600],{}," always scans the whole array and allocates an array just to discard everything but index ",[32,2840,758],{},[157,2842,2844,2846,2847,2849],{"className":2843},[160],[162,2845],{"disabled":90,"type":164}," Option A — ",[32,2848,600],{}," is guaranteed to be optimized by the engine for single-element access",[157,2851,2853,2855],{"className":2852},[160],[162,2854],{"disabled":90,"type":164}," They perform identically since both are O(n) in the worst case",[157,2857,2859,2861,2862,2865],{"className":2858},[160],[162,2860],{"disabled":90,"type":164}," Option B, but only because ",[32,2863,2864],{},"filter(...)​[0]"," is a syntax error",[195,2867,2868,2870,2881],{},[198,2869,200],{},[123,2871,2872,2874,2875,2835,2877,2838,2879],{},[204,2873,206],{}," A — Option B — ",[32,2876,2809],{},[32,2878,600],{},[32,2880,758],{},[123,2882,2883,165,2885,165,2888,2890,2891,2893,2894,2896,2897,2899],{},[204,2884,214],{},[204,2886,2887],{},"Performance:",[32,2889,2809],{}," short-circuits and returns the first matching element immediately, while ",[32,2892,600],{}," always iterates the entire array (even after finding a match) and builds a brand-new array — wasted work and a wasted allocation when all you wanted was one item. Both are technically O(n) worst case (no match found), but ",[32,2895,2809],{},"'s best\u002Faverage case is much better, and it never allocates. Prefer ",[32,2898,2809],{}," whenever you only need one result.",[14,2901,2902,2906,3066,3096],{"language":16},[18,2903,2905],{"id":2904},"q18-what-does-this-log","Q18. What does this log?",[23,2907,2908],{"language":16},[26,2909,2911],{"className":28,"code":2910,"language":16,"meta":30,"style":30},"const pipe = (...fns) => x => fns.reduce((acc, fn) => fn(acc), x);\n\nconst process = pipe(\n  s => s.trim(),\n  s => s.toLowerCase(),\n  s => s.replace(\u002F\\s+\u002Fg, '-')\n);\n\nconsole.log(process('  Hello World  '));\n",[32,2912,2913,2961,2965,2979,2995,3008,3040,3044,3048],{"__ignoreMap":30},[35,2914,2915,2917,2920,2922,2924,2926,2929,2931,2933,2936,2938,2941,2943,2945,2948,2950,2952,2954,2956,2958],{"class":37,"line":38},[35,2916,97],{"class":41},[35,2918,2919],{"class":45}," pipe",[35,2921,104],{"class":41},[35,2923,282],{"class":49},[35,2925,2118],{"class":41},[35,2927,2928],{"class":53},"fns",[35,2930,743],{"class":49},[35,2932,746],{"class":41},[35,2934,2935],{"class":53}," x",[35,2937,126],{"class":41},[35,2939,2940],{"class":49}," fns.",[35,2942,729],{"class":45},[35,2944,732],{"class":49},[35,2946,2947],{"class":53},"acc",[35,2949,57],{"class":49},[35,2951,2102],{"class":53},[35,2953,743],{"class":49},[35,2955,746],{"class":41},[35,2957,2148],{"class":45},[35,2959,2960],{"class":49},"(acc), x);\n",[35,2962,2963],{"class":37,"line":66},[35,2964,91],{"emptyLinePlaceholder":90},[35,2966,2967,2969,2972,2974,2976],{"class":37,"line":81},[35,2968,97],{"class":41},[35,2970,2971],{"class":100}," process",[35,2973,104],{"class":41},[35,2975,2919],{"class":45},[35,2977,2978],{"class":49},"(\n",[35,2980,2981,2984,2986,2989,2992],{"class":37,"line":87},[35,2982,2983],{"class":53},"  s",[35,2985,126],{"class":41},[35,2987,2988],{"class":49}," s.",[35,2990,2991],{"class":45},"trim",[35,2993,2994],{"class":49},"(),\n",[35,2996,2997,2999,3001,3003,3006],{"class":37,"line":94},[35,2998,2983],{"class":53},[35,3000,126],{"class":41},[35,3002,2988],{"class":49},[35,3004,3005],{"class":45},"toLowerCase",[35,3007,2994],{"class":49},[35,3009,3010,3012,3014,3016,3019,3021,3023,3026,3028,3030,3033,3035,3038],{"class":37,"line":141},[35,3011,2983],{"class":53},[35,3013,126],{"class":41},[35,3015,2988],{"class":49},[35,3017,3018],{"class":45},"replace",[35,3020,50],{"class":49},[35,3022,237],{"class":446},[35,3024,3025],{"class":100},"\\s",[35,3027,752],{"class":41},[35,3029,237],{"class":446},[35,3031,3032],{"class":41},"g",[35,3034,57],{"class":49},[35,3036,3037],{"class":446},"'-'",[35,3039,934],{"class":49},[35,3041,3042],{"class":37,"line":316},[35,3043,138],{"class":49},[35,3045,3046],{"class":37,"line":335},[35,3047,91],{"emptyLinePlaceholder":90},[35,3049,3050,3052,3054,3056,3059,3061,3064],{"class":37,"line":937},[35,3051,144],{"class":49},[35,3053,147],{"class":45},[35,3055,50],{"class":49},[35,3057,3058],{"class":45},"process",[35,3060,50],{"class":49},[35,3062,3063],{"class":446},"'  Hello World  '",[35,3065,352],{"class":49},[152,3067,3069,3075,3081,3087],{"className":3068},[155],[157,3070,3072,3074],{"className":3071},[160],[162,3073],{"disabled":90,"type":164}," 'hello-world'",[157,3076,3078,3080],{"className":3077},[160],[162,3079],{"disabled":90,"type":164}," 'Hello-World'",[157,3082,3084,3086],{"className":3083},[160],[162,3085],{"disabled":90,"type":164}," '-hello-world-'",[157,3088,3090,182,3092,3095],{"className":3089},[160],[162,3091],{"disabled":90,"type":164},[32,3093,3094],{},"pipe"," can't accept a variable number of functions",[195,3097,3098,3100,3105],{},[198,3099,200],{},[123,3101,3102,3104],{},[204,3103,206],{}," A — 'hello-world'",[123,3106,3107,165,3109,165,3111,3113,3114,3116,3117,3120,3121,3123,3124,3126,3127,3130,3131,3134,3135,3138,3139,3141,3142,3145],{},[204,3108,214],{},[204,3110,2045],{},[32,3112,3094],{}," is a standard function-composition utility built with ",[32,3115,729],{},": it threads the initial value ",[32,3118,3119],{},"x"," through each function in ",[32,3122,2928],{},", left to right, using each result as the input to the next. ",[32,3125,3063],{}," gets trimmed to ",[32,3128,3129],{},"'Hello World'",", lowercased to ",[32,3132,3133],{},"'hello world'",", then has its whitespace replaced with a dash, giving ",[32,3136,3137],{},"'hello-world'",". This ",[32,3140,729],{},"-over-functions pattern is a common, idiomatic way to build reusable pipelines instead of nesting calls manually (",[32,3143,3144],{},"f(g(h(x)))",").",[14,3147,3148,3156,3274,3315],{"language":16},[18,3149,3151,3152,3155],{"id":3150},"q19-whats-the-best-practice-benefit-of-writing-createlogger-this-way","Q19. What's the best-practice benefit of writing ",[32,3153,3154],{},"createLogger"," this way?",[23,3157,3158],{"language":16},[26,3159,3161],{"className":28,"code":3160,"language":16,"meta":30,"style":30},"const createLogger = level => message => console.log(`[${level}] ${message}`);\n\nconst logError = createLogger('ERROR');\nconst logInfo = createLogger('INFO');\n\nlogError('Disk full');\nlogInfo('Server started');\n",[32,3162,3163,3206,3210,3228,3246,3250,3262],{"__ignoreMap":30},[35,3164,3165,3167,3170,3172,3175,3177,3180,3182,3185,3187,3189,3192,3195,3198,3201,3204],{"class":37,"line":38},[35,3166,97],{"class":41},[35,3168,3169],{"class":45}," createLogger",[35,3171,104],{"class":41},[35,3173,3174],{"class":53}," level",[35,3176,126],{"class":41},[35,3178,3179],{"class":53}," message",[35,3181,126],{"class":41},[35,3183,3184],{"class":49}," console.",[35,3186,147],{"class":45},[35,3188,50],{"class":49},[35,3190,3191],{"class":446},"`[${",[35,3193,3194],{"class":49},"level",[35,3196,3197],{"class":446},"}] ${",[35,3199,3200],{"class":49},"message",[35,3202,3203],{"class":446},"}`",[35,3205,138],{"class":49},[35,3207,3208],{"class":37,"line":66},[35,3209,91],{"emptyLinePlaceholder":90},[35,3211,3212,3214,3217,3219,3221,3223,3226],{"class":37,"line":81},[35,3213,97],{"class":41},[35,3215,3216],{"class":100}," logError",[35,3218,104],{"class":41},[35,3220,3169],{"class":45},[35,3222,50],{"class":49},[35,3224,3225],{"class":446},"'ERROR'",[35,3227,138],{"class":49},[35,3229,3230,3232,3235,3237,3239,3241,3244],{"class":37,"line":87},[35,3231,97],{"class":41},[35,3233,3234],{"class":100}," logInfo",[35,3236,104],{"class":41},[35,3238,3169],{"class":45},[35,3240,50],{"class":49},[35,3242,3243],{"class":446},"'INFO'",[35,3245,138],{"class":49},[35,3247,3248],{"class":37,"line":94},[35,3249,91],{"emptyLinePlaceholder":90},[35,3251,3252,3255,3257,3260],{"class":37,"line":141},[35,3253,3254],{"class":45},"logError",[35,3256,50],{"class":49},[35,3258,3259],{"class":446},"'Disk full'",[35,3261,138],{"class":49},[35,3263,3264,3267,3269,3272],{"class":37,"line":316},[35,3265,3266],{"class":45},"logInfo",[35,3268,50],{"class":49},[35,3270,3271],{"class":446},"'Server started'",[35,3273,138],{"class":49},[152,3275,3277,3286,3299,3305],{"className":3276},[155],[157,3278,3280,3282,3283,3285],{"className":3279},[160],[162,3281],{"disabled":90,"type":164}," It lets you \"lock in\" the ",[32,3284,3194],{}," argument once via partial application, producing specialized, reusable functions instead of repeating the level at every call site",[157,3287,3289,3291,3292,3294,3295,3298],{"className":3288},[160],[162,3290],{"disabled":90,"type":164}," It's purely stylistic — passing ",[32,3293,3194],{}," as a normal second argument to a single ",[32,3296,3297],{},"log(level, message)"," function would be identical in every way",[157,3300,3302,3304],{"className":3301},[160],[162,3303],{"disabled":90,"type":164}," Currying here makes the logger run faster than a two-argument function would",[157,3306,3308,3310,3311,3314],{"className":3307},[160],[162,3309],{"disabled":90,"type":164}," It's required — ",[32,3312,3313],{},"console.log"," cannot be called with a template literal directly",[195,3316,3317,3319,3326],{},[198,3318,200],{},[123,3320,3321,3323,3324,3285],{},[204,3322,206],{}," A — It lets you \"lock in\" the ",[32,3325,3194],{},[123,3327,3328,165,3330,3332,3333,3335,3336,3338,3339,3341,3342,237,3344,3346,3347,3350],{},[204,3329,214],{},[204,3331,2045],{}," this is a textbook, practical use of currying: ",[32,3334,3194],{}," is a configuration-like argument that's known up front and reused many times, while ",[32,3337,3200],{}," varies per call. Currying ",[32,3340,3154],{}," lets you produce ",[32,3343,3254],{},[32,3345,3266],{}," once and then call them like ordinary single-argument functions everywhere else, instead of writing ",[32,3348,3349],{},"log('ERROR', ...)"," at every call site and risking a copy-pasted wrong level string.",[14,3352,3353,3357,3455,3486],{"language":16},[18,3354,3356],{"id":3355},"q20-is-deep-currying-like-this-a-good-practice-when-all-five-arguments-are-always-supplied-together-at-one-call-site","Q20. Is deep currying like this a good practice when all five arguments are always supplied together at one call site?",[23,3358,3359],{"language":16},[26,3360,3362],{"className":28,"code":3361,"language":16,"meta":30,"style":30},"const add5 = curry(a => b => c => d => e => a + b + c + d + e);\nconsole.log(add5(1)(2)(3)(4)(5));\n",[32,3363,3364,3422],{"__ignoreMap":30},[35,3365,3366,3368,3371,3373,3375,3377,3379,3381,3383,3385,3388,3390,3393,3395,3398,3400,3402,3404,3407,3409,3412,3414,3417,3419],{"class":37,"line":38},[35,3367,97],{"class":41},[35,3369,3370],{"class":100}," add5",[35,3372,104],{"class":41},[35,3374,2097],{"class":45},[35,3376,50],{"class":49},[35,3378,962],{"class":53},[35,3380,126],{"class":41},[35,3382,1108],{"class":53},[35,3384,126],{"class":41},[35,3386,3387],{"class":53}," c",[35,3389,126],{"class":41},[35,3391,3392],{"class":53}," d",[35,3394,126],{"class":41},[35,3396,3397],{"class":53}," e",[35,3399,126],{"class":41},[35,3401,974],{"class":49},[35,3403,752],{"class":41},[35,3405,3406],{"class":49}," b ",[35,3408,752],{"class":41},[35,3410,3411],{"class":49}," c ",[35,3413,752],{"class":41},[35,3415,3416],{"class":49}," d ",[35,3418,752],{"class":41},[35,3420,3421],{"class":49}," e);\n",[35,3423,3424,3426,3428,3430,3433,3435,3437,3439,3441,3443,3445,3447,3449,3451,3453],{"class":37,"line":66},[35,3425,144],{"class":49},[35,3427,147],{"class":45},[35,3429,50],{"class":49},[35,3431,3432],{"class":45},"add5",[35,3434,50],{"class":49},[35,3436,568],{"class":100},[35,3438,1135],{"class":49},[35,3440,330],{"class":100},[35,3442,1135],{"class":49},[35,3444,577],{"class":100},[35,3446,1135],{"class":49},[35,3448,582],{"class":100},[35,3450,1135],{"class":49},[35,3452,349],{"class":100},[35,3454,352],{"class":49},[152,3456,3458,3468,3474,3480],{"className":3457},[155],[157,3459,3461,3463,3464,3467],{"className":3460},[160],[162,3462],{"disabled":90,"type":164}," No — currying pays off when arguments arrive separately over time (partial application); when they always arrive together, a plain ",[32,3465,3466],{},"(a, b, c, d, e) => ..."," function is clearer and easier to debug",[157,3469,3471,3473],{"className":3470},[160],[162,3472],{"disabled":90,"type":164}," Yes — currying should always be preferred for functional purity, regardless of call pattern",[157,3475,3477,3479],{"className":3476},[160],[162,3478],{"disabled":90,"type":164}," No — curried functions are fundamentally incapable of accepting more than one argument per call",[157,3481,3483,3485],{"className":3482},[160],[162,3484],{"disabled":90,"type":164}," Yes — curried chains are always faster than an equivalent multi-parameter function",[195,3487,3488,3490,3497],{},[198,3489,200],{},[123,3491,3492,3494,3495,3467],{},[204,3493,206],{}," A — No — currying pays off when arguments arrive separately over time (partial application); when they always arrive together, a plain ",[32,3496,3466],{},[123,3498,3499,165,3501,3503],{},[204,3500,214],{},[204,3502,2045],{}," currying's real value (as in Q19) is enabling partial application — supplying some arguments now and the rest later, at a different place in the code. When every argument is always known and passed at the same call site, chaining five single-argument calls adds indirection, produces longer\u002Fharder-to-read stack traces, and gives no practical benefit over a single multi-parameter function. Good judgment means reaching for currying where it solves a real problem (config-then-use, building specialized functions), not applying it uniformly everywhere as a stylistic default.",[3505,3506,3507],"style",{},"html pre.shiki code .svdQ7, html code.shiki .svdQ7{--shiki-default:#D73A49;--shiki-github-dark:#F97583}html pre.shiki code .sIsaT, html code.shiki .sIsaT{--shiki-default:#6F42C1;--shiki-github-dark:#B392F0}html pre.shiki code .ssxIu, html code.shiki .ssxIu{--shiki-default:#24292E;--shiki-github-dark:#E1E4E8}html pre.shiki code .sCrzJ, html code.shiki .sCrzJ{--shiki-default:#E36209;--shiki-github-dark:#FFAB70}html pre.shiki code .snvgF, html code.shiki .snvgF{--shiki-default:#005CC5;--shiki-github-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .github-dark .shiki span {color: var(--shiki-github-dark);background: var(--shiki-github-dark-bg);font-style: var(--shiki-github-dark-font-style);font-weight: var(--shiki-github-dark-font-weight);text-decoration: var(--shiki-github-dark-text-decoration);}html.github-dark .shiki span {color: var(--shiki-github-dark);background: var(--shiki-github-dark-bg);font-style: var(--shiki-github-dark-font-style);font-weight: var(--shiki-github-dark-font-weight);text-decoration: var(--shiki-github-dark-text-decoration);}html pre.shiki code .sJ6F3, html code.shiki .sJ6F3{--shiki-default:#032F62;--shiki-github-dark:#9ECBFF}html pre.shiki code .sdCPZ, html code.shiki .sdCPZ{--shiki-default:#6A737D;--shiki-github-dark:#6A737D}",{"title":30,"searchDepth":66,"depth":66,"links":3509},[3510,3511,3512,3513,3514,3515,3516,3517,3518,3519,3520,3521,3522,3524,3525,3526,3527,3528,3529,3531],{"id":20,"depth":81,"text":21},{"id":250,"depth":81,"text":251},{"id":423,"depth":81,"text":424},{"id":546,"depth":81,"text":547},{"id":681,"depth":81,"text":682},{"id":825,"depth":81,"text":826},{"id":1083,"depth":81,"text":1084},{"id":1215,"depth":81,"text":1216},{"id":1357,"depth":81,"text":1358},{"id":1459,"depth":81,"text":1460},{"id":1550,"depth":81,"text":1551},{"id":1792,"depth":81,"text":1793},{"id":1926,"depth":81,"text":3523},"Q13. Why does .map(Number) behave correctly while .map(parseInt) (Q8) does not?",{"id":2082,"depth":81,"text":2083},{"id":2386,"depth":81,"text":2387},{"id":2558,"depth":81,"text":2559},{"id":2737,"depth":81,"text":2738},{"id":2904,"depth":81,"text":2905},{"id":3150,"depth":81,"text":3530},"Q19. What's the best-practice benefit of writing createLogger this way?",{"id":3355,"depth":81,"text":3356},"md",{},"\u002Fjs\u002F13-higher-order-functions",{"title":5,"description":30},"js\u002F13-higher-order-functions","ywq6JmMeDkXpj8wM20L2m4-no6iAH5iOyRbU6Cz-CVo",1787335397334]