1 The `uniq()` function extracts the unique set of all values within the 2 given input array, maintaining the original order. 3 4 Returns an array containing all unique items of the input array. 5 6 Returns `null` if the input is not an array value. 7 8 -- Testcase -- 9 {% 10 let o1 = { an: "object" }; 11 let o2 = { an: "object" }; // same but not identical 12 13 let a1 = [ 1, 2, 3 ]; 14 let a2 = [ 1, 2, 3 ]; // same but not identical 15 16 printf("%.J\n", [ 17 // strict comparison is used, 0 and "0" are not unique 18 uniq([ 0, 1, 2, 0, "0", 2, 3, "4", 4 ]), 19 20 // despite NaN != NaN, two NaN values are not unique 21 uniq([ NaN, NaN ]), 22 23 // only identical objects are filtered, not equivalent ones 24 uniq([ o1, o1, o2, a1, a1, a2 ]), 25 26 // invalid input yields `null` 27 uniq(true) 28 ]); 29 %} 30 -- End -- 31 32 -- Expect stdout -- 33 [ 34 [ 35 0, 36 1, 37 2, 38 "0", 39 3, 40 "4", 41 4 42 ], 43 [ 44 "NaN" 45 ], 46 [ 47 { 48 "an": "object" 49 }, 50 { 51 "an": "object" 52 }, 53 [ 54 1, 55 2, 56 3 57 ], 58 [ 59 1, 60 2, 61 3 62 ] 63 ], 64 null 65 ] 66 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt