{"ScriptPreparationCode":"const array = [];\r\n\r\nfor (let i = 0; i \u003C 100; i\u002B\u002B) {\r\n array.push({\r\n key: i,\r\n \u0022status\u0022: \u0022Published\u0022,\r\n \u0022npoId\u0022: 37,\r\n \u0022directionId\u0022: 1,\r\n \u0022title\u0022: \u0022QWERTYU QWERTYU QWERTY\u0022,\r\n \u0022subtitle\u0022: null,\r\n \u0022description\u0022: \u0022Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer cursus fermentum commodo. Nullam hendrerit lectus quis tincidunt scelerisque. Suspendisse turpis augue, dignissim non molestie id, tempus tristique diam. Donec semper augue purus, et fermentum nibh laoreet ac. Pellentesque ac libero ac mauris bibendum pretium. Duis convallis vulputate dolor vitae semper. In eget ante dictum, vulputate nunc sit amet, consequat tortor. Vivamus et lorem tortor. Mauris venenatis risus et lobortis convallis. Vestibulum eros lectus, rhoncus id tincidunt non, faucibus dapibus sapien. Ut risus massa, pellentesque ac aliquam vitae, lobortis vel magna. Mauris in consectetur lorem.\\nDonec imperdiet non sem at fermentum. Proin faucibus quis dui vestibulum hendrerit. Aenean pharetra sed quam vel egestas. Maecenas mattis nec quam consequat blandit. Aliquam viverra, velit vitae condimentum porttitor, dolor neque pretium dolor, a molestie urna risus vel neque. Nullam vitae erat a magna porttitor elementum. Aenean egestas auctor magna, eu rhoncus nisl blandit sed. Phasellus malesuada tempor auctor. Pellentesque non odio vel lectus rutrum condimentum.\\nDonec porta vitae velit nec pellentesque. Duis tristique molestie ante, nec accumsan nibh. Aliquam consectetur ullamcorper nunc eu egestas. Vivamus luctus nulla et diam porta, in efficitur mi sagittis. Mauris eu sapien imperdiet, ultricies arcu quis, placerat justo. Integer vel mi in enim congue semper sit amet non purus. Pellentesque varius felis eu sem semper lobortis. Maecenas finibus congue felis quis tristique. Donec sit amet massa at sem vehicula luctus eu et massa. Nam id tortor sed magna volutpat dictum in id orci. Proin ac nulla id turpis maximus posuere.\\nInteger vel arcu lacinia, malesuada enim vel, iaculis nisi. Nullam consectetur, elit eget varius auctor, arcu mi aliquet nisl, non pellentesque justo leo et ante. Aenean eu commodo quam, sed iaculis orci. Donec auctor odio nec sapien fringilla dignissim. Maecenas facilisis sit amet ipsum tincidunt tempor. Morbi dapibus ipsum et leo iaculis, a hendrerit arcu cursus. Sed in auctor risus, vitae ultricies mauris. Nunc ultricies maximus turpis, in malesuada leo posuere ac. Maecenas cursus elit et augue porta auctor. In consequat purus sit amet cursus rutrum. Integer ut purus aliquet, semper justo mollis, tincidunt tellus. Vivamus tortor neque, vulputate facilisis aliquet tempus, tempor at sapien. Aliquam et purus tincidunt magna vulputate aliquam viverra sit amet ex. In hac dui.\u0022,\r\n \u0022customization\u0022: \u0022QWERTYUQWERTYU2021\u0022,\r\n \u0022avatar\u0022: \u0022https://QQWERTYUIOIUYTRE/uploads/stories/story_avatar_1525702925760.jpeg\u0022,\r\n \u0022customImage\u0022: null,\r\n \u0022sharingImage\u0022: null,\r\n \u0022requiredAmount\u0022: 120000000,\r\n \u0022collectedAmount\u0022: 0,\r\n \u0022donatorsCount\u0022: 0,\r\n \u0022expiresAt\u0022: \u00222018-12-15T20:59:59.000Z\u0022,\r\n \u0022promotion\u0022: null,\r\n \u0022city\u0022: { \u0022name\u0022: \u0022\u041C\u043E\u0441\u043A\u0432\u0430\u0022, \u0022__typename\u0022: \u0022City\u0022 },\r\n \u0022metaInformation\u0022: {\r\n \u0022description\u0022: \u0022\u0411\u043B\u0430\u0433\u043E\u0442\u0432\u043E\u0440\u0438\u0442\u0435\u043B\u044C\u043D\u044B\u0439 \u0444\u043E\u043D\u0434 QWERTY QWERTY\u0022,\r\n \u0022__typename\u0022: \u0022MetaInformation\u0022\r\n },\r\n \u0022npo\u0022: {\r\n \u0022title\u0022: \u0022QWERTYUI\u0022,\r\n \u0022imgUrl\u0022: \u0022https://dev.bllablaca.ru/entities/entity-1493723743044_app.png\u0022,\r\n \u0022__typename\u0022: \u0022ShortNpo\u0022\r\n },\r\n \u0022__typename\u0022: \u0022Story\u0022\r\n })\r\n}\r\n\r\nfunction hashmap () { return array.reduce((mapper, next) =\u003E ({\r\n ...mapper,\r\n [next.key]: next\r\n}), {});}\r\n\r\nlet hashmap1;\r\n\r\nfunction findInArray (key) {\r\n const index = bs(array, key, function(element, needle) {\r\n return element.key - needle;\r\n });\r\n return index \u003E 0 ? array[index] : undefined;\r\n}\r\n\r\nfunction findArrayFind (key) {\r\n return array.find(elem=\u003Eelem.key===key);\r\n}\r\n\r\nfunction findInHashMap (key) {\r\n if (!hashmap1) {\r\n hashmap1 = hashmap();\r\n }\r\n return hashmap1[key] || undefined;\r\n}\r\n\r\nfunction findInArrayByPolling (key) {\r\n for (let i = 0, len = array.length ; i \u003C len; i\u002B\u002B) {\r\n if (array[i].key === key) {\r\n return array[i]\r\n }\r\n }\r\n}\r\n\r\n\r\n\r\nfunction bs(haystack, needle, comparator, low, high) {\r\n var mid, cmp;\r\n \r\n if(low === undefined)\r\n low = 0;\r\n \r\n else {\r\n low = low|0;\r\n if(low \u003C 0 || low \u003E= haystack.length)\r\n throw new RangeError(\u0022invalid lower bound\u0022);\r\n }\r\n \r\n if(high === undefined)\r\n high = haystack.length - 1;\r\n \r\n else {\r\n high = high|0;\r\n if(high \u003C low || high \u003E= haystack.length)\r\n throw new RangeError(\u0022invalid upper bound\u0022);\r\n }\r\n \r\n while(low \u003C= high) {\r\n // The naive \u0060low \u002B high \u003E\u003E\u003E 1\u0060 could fail for array lengths \u003E 2**31\r\n // because \u0060\u003E\u003E\u003E\u0060 converts its operands to int32. \u0060low \u002B (high - low \u003E\u003E\u003E 1)\u0060\r\n // works for array lengths \u003C= 2**32-1 which is also Javascript\u0027s max array\r\n // length.\r\n mid = low \u002B ((high - low) \u003E\u003E\u003E 1);\r\n cmp = \u002Bcomparator(haystack[mid], needle, mid, haystack);\r\n \r\n // Too low.\r\n if(cmp \u003C 0.0)\r\n low = mid \u002B 1;\r\n \r\n // Too high.\r\n else if(cmp \u003E 0.0)\r\n high = mid - 1;\r\n \r\n // Key found.\r\n else\r\n return mid;\r\n }\r\n \r\n // Key not found.\r\n return ~low;\r\n}\r\n","TestCases":[{"Name":"find by binary search array","Code":"const target = Math.floor(Math.random() * 100);\r\nfindInArray(target);","IsDeferred":false},{"Name":"find by array polling","Code":"const target = Math.floor(Math.random() * 100);\r\nfindInArrayByPolling(target);","IsDeferred":false},{"Name":"find by hashmap","Code":"const target = Math.floor(Math.random() * 100);\r\nfindInHashMap(target);","IsDeferred":false},{"Name":"find by func find","Code":"const target = Math.floor(Math.random() * 100);\r\nfindArrayFind(target)","IsDeferred":false}]}