{"ScriptPreparationCode":"/* make a new array with 15k items */\r\nvar arr = new Array(15000);\r\n\r\n/* fill array tems with basic object */\r\narr.fill({ id: 0 });\r\n\r\n/* generate 2 random numbers in our 15k range */\r\nvar foo = Math.floor(Math.random() * 15000);\r\nvar bar = Math.floor(Math.random() * 15000);\r\n\r\n/* set the index of arr[foo] to foo for our tests */\r\narr[foo].id = foo;","TestCases":[{"Name":"findIndex","Code":"const bookFreePlatform = (arr, foo, bar) =\u003E {\r\n\r\n /* find array index where id == foo */\r\n var index = arr.findIndex(item =\u003E item.id === foo);\r\n\r\n /* findIndex returns -1 on fail, so test for that */\r\n if ( index != -1 ) {\r\n\r\n /* ok, we have an index, lets edit that entry, and console log it for fun */\r\n arr[index].id = bar;\r\n console.log(arr[index]);\r\n }\r\n\r\n /* return altered array */\r\n return arr;\r\n}\r\n\r\nbookFreePlatform(arr, foo, bar);","IsDeferred":false},{"Name":"for loop","Code":"const bookFreePlatform = (arr, foo, bar) =\u003E {\r\n\r\n /* find array item where id == foo */\r\n for (let i = 0; i \u003C arr.length; i\u002B\u002B) {\r\n\r\n /* not an error check, just a simple comparison */\r\n if (arr[i].id === foo) {\r\n\r\n /* if we got here, it found and index, lets edit it and log it again */\r\n arr[i].id = bar;\r\n console.log(arr[i]);\r\n\r\n /* stop the loop to save time and resources, we\u0027re done */\r\n break;\r\n }\r\n }\r\n\r\n /* return altered array */\r\n return arr;\r\n}\r\n\r\nbookFreePlatform(arr, foo, bar);","IsDeferred":false},{"Name":"Map \u002B IndexOf","Code":"const bookFreePlatform = (arr, foo, bar) =\u003E {\r\n\r\n /* find array index where id == foo */\r\n var index = arr.map(item =\u003E item.id).indexOf(foo);\r\n\r\n /* findIndex returns -1 on fail, so test for that */\r\n if ( index != -1 ) {\r\n\r\n /* ok, we have an index, lets edit that entry, and console log it for fun */\r\n arr[index].id = bar;\r\n console.log(arr[index]);\r\n }\r\n\r\n /* return altered array */\r\n return arr;\r\n}\r\n\r\nbookFreePlatform(arr, foo, bar);","IsDeferred":false}]}