Best JavaScript code snippet using storybook-root
function.js
Source:function.js
1/**2 * Created by rrr on 14-5-26.3 */4Array.prototype.search = function (v) {5 var result = [];6 if (v.constructor.toString() == Array) {7 for (i = 0; i < v.length; i++) {8 for (j = 0; j < this.length; j++) {9 if (this[j].toString() == v[i].toString()) {10 result.push(j);11 }12 }13 }14 }15 else if (v.constructor.toString() == String || v.constructor.toString() == Number) {16 for (j in this) {17 if (this[j] == v) {18 result.push(j);19 }20 }21 }22 if (result) return result;23 else return -1;24}25function getSelectOption_single() {26 var sled = [];27 $(".q-list li").each(function () {28 if ($(this).find("label").attr("isSed") == "true") {29 sled.push($(this).find("label").attr("o_index"));30 return;31 }32 })33 return sled;34}35function getSelectOption_multi() {36 var sled = [];37 $(".q-list li").each(function () {38 if ($(this).find("label").attr("isSed") == "true") {39 sled.push($(this).find("label").attr("o_index"));40 }41 })42 return sled;43}44function getSelection_options(questionId) {45 var answers, result=[];46 if ($.cookie("C2B_questions_answer") != undefined && $.cookie("C2B_questions_answer") != "null") {47 answers = JSON.parse($.cookie("C2B_questions_answer"));48 }49 if (answers) {50 for (i=0;i<answers.length;i++) {51 if (answers[i].id == parseInt(questionId)+1) result = answers[i].answer;52 }53 }54 return result;55}56function nextIndex_q1() {57 var q1_selection = getSelection_options(0);58 if (q1_selection.length == 0) {59 return -3;60 }61 else if (q1_selection.search(4).length > 0) {62 send_survey();63 return -5;64 }65 else {66 return 1;67 }68}69function nextIndex_q2() {70 var q1_selection = getSelection_options(0);71 var q2_selection = getSelection_options(1);72 var nextIndex;73 if (q2_selection.length == 0) nextIndex = -3;74 else{75 if ([0, 1, 2].search(q1_selection).length > 0) {76 nextIndex = 2;77 }78 else {79 nextIndex = 12;80 }81 }82 if (nextIndex) return nextIndex;83 else return -1;84}85function nextIndex_q3() {86 var q3_selection = getSelection_options(2);87 var q1_selection = getSelection_options(0);88 var nextIndex;89 if (q3_selection.length == 0) nextIndex = -3;90 else if (q3_selection.length > 3) {91 nextIndex = 3;92 }93 else {94 if ([0, 1].search(q1_selection).length == 0) {95 nextIndex = 12;96 }97 else {98 if (q3_selection.search(3).length > 0) nextIndex = 4;99 else {100 if (q3_selection.search(4).length > 0) nextIndex = 5;101 else {102 if (q3_selection.search(5).length > 0) nextIndex = 6;103 else {104 if (q3_selection.search(6).length > 0) nextIndex = 7;105 else {106 if (q3_selection.search(7).length > 0) nextIndex = 8;107 else {108 if (q3_selection.search(9).length > 0) nextIndex = 9;109 else {110 if (q3_selection.search(10).length > 0) nextIndex = 10;111 else {112 if (q3_selection.search(14).length > 0) nextIndex = 11;113 else {114 nextIndex = 12;115 }116 }117 }118 }119 }120 }121 }122 }123 }124 }125 if (nextIndex) return nextIndex;126 else -1;127}128//第åé¢129function nextIndex_q4() {130 var q4_selection = getSelection_options(3);131 var q1_selection = getSelection_options(0);132 var nextIndex;133 if (q4_selection.length == 0) {134 nextIndex = -3;135 }136 else{137 if(q4_selection.length>3){138 nextIndex=-4;139 }140 else {141 if ([0, 1].search(q1_selection).length== 0) {142 nextIndex = 12;143 }144 else {145 if (q4_selection.search(3).length > 0) nextIndex = 4;146 else {147 if (q4_selection.search(4).length > 0) nextIndex = 5;148 else {149 if (q4_selection.search(5).length > 0) nextIndex = 6;150 else {151 if (q4_selection.search(6).length > 0) nextIndex = 7;152 else {153 if (q4_selection.search(7).length > 0) nextIndex = 8;154 else {155 if (q4_selection.search(9).length > 0) nextIndex = 9;156 else {157 if (q4_selection.search(10).length > 0) nextIndex = 10;158 else {159 if (q4_selection.search(14).length > 0) nextIndex = 11;160 else {161 nextIndex = 12;162 }163 }164 }165 }166 }167 }168 }169 }170 }171 }172 }173 if (nextIndex) return nextIndex;174 else return -1;175}176//第äºé¢177function nextIndex_q5() {178 var q3_selection = getSelection_options(2);179 var q4_selection = getSelection_options(3);180 var q5_selection = getSelection_options(4);181 var nextIndex;182 if(q5_selection.length==0){183 nextIndex=-3;184 }185 else{186 if (q4_selection == -1) {187 if (q3_selection.search(4).length > 0) nextIndex = 5;188 else {189 if (q3_selection.search(5).length > 0) nextIndex = 6;190 else {191 if (q3_selection.search(6).length > 0) nextIndex = 7;192 else {193 if (q3_selection.search(7).length > 0) nextIndex = 8;194 else {195 if (q3_selection.search(9).length > 0) nextIndex = 9;196 else {197 if (q3_selection.search(10).length > 0) nextIndex = 10;198 else {199 if (q3_selection.search(14).length > 0) nextIndex = 11;200 else {201 nextIndex = 12;202 }203 }204 }205 }206 }207 }208 }209 }210 else {211 if (q4_selection.search(4).length > 0) nextIndex = 5;212 else {213 if (q4_selection.search(5).length > 0) nextIndex = 6;214 else {215 if (q4_selection.search(6).length > 0) nextIndex = 7;216 else {217 if (q4_selection.search(7).length > 0) nextIndex = 8;218 else {219 if (q4_selection.search(9).length > 0) nextIndex = 9;220 else {221 if (q4_selection.search(10).length > 0) nextIndex = 10;222 else {223 if (q4_selection.search(14).length > 0) nextIndex = 11;224 else {225 nextIndex = 12;226 }227 }228 }229 }230 }231 }232 }233 }234 }235 if (nextIndex) return nextIndex;236 else return -1;237}238//第å
é¢239function nextIndex_q6() {240 var q3_selection = getSelection_options(2);241 var q4_selection = getSelection_options(3);242 var q6_selection = getSelection_options(5);243 var nextIndex;244 if(q6_selection.length==0){245 nextIndex=-3;246 }247 else{248 if (q4_selection == -1) {249 if (q3_selection.search(5).length > 0) nextIndex = 6;250 else {251 if (q3_selection.search(6).length > 0) nextIndex = 7;252 else {253 if (q3_selection.search(7).length > 0) nextIndex = 8;254 else {255 if (q3_selection.search(9).length > 0) nextIndex = 9;256 else {257 if (q3_selection.search(10).length > 0) nextIndex = 10;258 else {259 if (q3_selection.search(14).length > 0) nextIndex = 11;260 else {261 nextIndex = 12;262 }263 }264 }265 }266 }267 }268 }269 else {270 if (q4_selection.search(5).length > 0) nextIndex = 6;271 else {272 if (q4_selection.search(6).length > 0) nextIndex = 7;273 else {274 if (q4_selection.search(7).length > 0) nextIndex = 8;275 else {276 if (q4_selection.search(9).length > 0) nextIndex = 9;277 else {278 if (q4_selection.search(10).length > 0) nextIndex = 10;279 else {280 if (q4_selection.search(14).length > 0) nextIndex = 11;281 else {282 nextIndex = 12;283 }284 }285 }286 }287 }288 }289 }290 }291 if (nextIndex) return nextIndex;292 else return -1;293}294//第ä¸é¢295function nextIndex_q7() {296 var q3_selection = getSelection_options(2);297 var q4_selection = getSelection_options(3);298 var q7_selection = getSelection_options(6);299 var nextIndex;300 if(q7_selection.length==0){301 nextIndex=-1;302 }303 else{304 if (q4_selection == -1) {305 if (q3_selection.search(6).length > 0) nextIndex = 7;306 else {307 if (q3_selection.search(7).length > 0) nextIndex = 8;308 else {309 if (q3_selection.search(9).length > 0) nextIndex = 9;310 else {311 if (q3_selection.search(10).length > 0) nextIndex = 10;312 else {313 if (q3_selection.search(14).length > 0) nextIndex = 11;314 else {315 nextIndex = 12;316 }317 }318 }319 }320 }321 }322 else {323 if (q4_selection.search(6).length > 0) nextIndex = 7;324 else {325 if (q4_selection.search(7).length > 0) nextIndex = 8;326 else {327 if (q4_selection.search(9).length > 0) nextIndex = 9;328 else {329 if (q4_selection.search(10).length > 0) nextIndex = 10;330 else {331 if (q4_selection.search(14).length > 0) nextIndex = 11;332 else {333 nextIndex = 12;334 }335 }336 }337 }338 }339 }340 }341 if (nextIndex) return nextIndex;342 else return -1;343}344//第å
«é¢345function nextIndex_q8() {346 var q3_selection = getSelection_options(2);347 var q4_selection = getSelection_options(3);348 var q8_selection = getSelection_options(7);349 var nextIndex;350 if(q8_selection.length==0){351 nextIndex=-3;352 }353 else{354 if (q4_selection == -1) {355 if (q3_selection.search(7).length > 0) nextIndex = 8;356 else {357 if (q3_selection.search(9).length > 0) nextIndex = 9;358 else {359 if (q3_selection.search(10).length > 0) nextIndex = 10;360 else {361 if (q3_selection.search(14).length > 0) nextIndex = 11;362 else {363 nextIndex = 12;364 }365 }366 }367 }368 }369 else {370 if (q4_selection.search(7).length > 0) nextIndex = 8;371 else {372 if (q4_selection.search(9).length > 0) nextIndex = 9;373 else {374 if (q4_selection.search(10).length > 0) nextIndex = 10;375 else {376 if (q4_selection.search(14).length > 0) nextIndex = 11;377 else {378 nextIndex = 12;379 }380 }381 }382 }383 }384 }385 if (nextIndex) return nextIndex;386 else return -1;387}388//第ä¹é¢389function nextIndex_q9() {390 var q3_selection = getSelection_options(2);391 var q4_selection = getSelection_options(3);392 var q9_selection = getSelection_options(8);393 var nextIndex;394 if(q9_selection.length==0){395 nextIndex=-3;396 }397 else{398 if (q4_selection == -1) {399 if (q3_selection.search(9).length > 0) nextIndex = 9;400 else {401 if (q3_selection.search(10).length > 0) nextIndex = 10;402 else {403 if (q3_selection.search(14).length > 0) nextIndex = 11;404 else {405 nextIndex = 12;406 }407 }408 }409 }410 else {411 if (q4_selection.search(9).length > 0) nextIndex = 9;412 else {413 if (q4_selection.search(10).length > 0) nextIndex = 10;414 else {415 if (q4_selection.search(14).length > 0) nextIndex = 11;416 else {417 nextIndex = 12;418 }419 }420 }421 }422 }423 if (nextIndex) return nextIndex;424 else return -1;425}426//第åé¢427function nextIndex_q10() {428 var q3_selection = getSelection_options(2);429 var q4_selection = getSelection_options(3);430 var q10_selection = getSelection_options(9);431 var nextIndex;432 if(q10_selection.length==0){433 nextIndex=-3;434 }435 else{436 if (q4_selection == -1) {437 if (q3_selection.search(10).length > 0) nextIndex = 10;438 else {439 if (q3_selection.search(14).length > 0) nextIndex = 11;440 else {441 nextIndex = 12;442 }443 }444 }445 else {446 if (q4_selection.search(10).length > 0) nextIndex = 10;447 else {448 if (q4_selection.search(14).length > 0) nextIndex = 11;449 else {450 nextIndex = 12;451 }452 }453 }454 }455 if (nextIndex) return nextIndex;456 else return -1;457}458//第åä¸é¢459function nextIndex_q11() {460 var q3_selection = getSelection_options(2);461 var q4_selection = getSelection_options(3);462 var q11_selection = getSelection_options(10);463 var nextIndex;464 if(q11_selection.length==0){465 nextIndex=-3;466 }467 else{468 if (q4_selection == -1) {469 if (q3_selection.search(14).length > 0) nextIndex = 11;470 else {471 nextIndex = 12;472 }473 }474 else {475 if (q4_selection.search(14).length > 0) nextIndex = 11;476 else {477 nextIndex = 12;478 }479 }480 }481 if (nextIndex) return nextIndex;482 else return -1;483}484function nextIndex_q12() {485 var q12_selection = getSelection_options(11);486 if(q12_selection.length==0) return -3;487 else return 12;488}489function nextIndex_q13() {490 var nextIndex;491 var q13_selection = getSelection_options(12);492 if(q13_selection.length==0) nextIndex=-3;493 else if (q13_selection.search(0).length > 0) nextIndex = 13;494 else {495 nextIndex = 14;496 }497 if (nextIndex) return nextIndex;498 else return -1;499}500function nextIndex_q14() {501 return 14;502}503function nextIndex_q15() {504 var nextIndex;505 var q15_selection = getSelection_options(14);506 if(q15_selection.length==0) nextIndex=-3;507 else if (q15_selection.search(1).length > 0) {508 send_survey();509 nextIndex =-5;510 }511 else {512 nextIndex = 15;513 }514 if (nextIndex) return nextIndex;515 else return -1;516}517function nextIndex_q16() {518 var q15_selection = getSelection_options(15);519 if(q15_selection.length==0) return -3;520 else {521 send_survey();522 return -5;523 };524}525function saveAnswer(questionId, options) {526 var data;527 var customFill = $(".custom-fill").val() || ""528 if(customFill=="Please specify") customFill="";529 if ($.cookie("C2B_questions_answer") == undefined || $.cookie("C2B_questions_answer") == "null") {530 data = [];531 }532 else {533 data = JSON.parse($.cookie("C2B_questions_answer"))534 }535 var isset = false;536 if (data) {537 for (i in data) {538 if (data[i].id == parseInt(questionId)+1) {539 data[i].answer = options;540 data[i].fill = customFill;541 isset = true;542 }543 }544 }545 if (!isset) data.push({"id": parseInt(questionId)+1, "answer": options, "fill": customFill});546 $.cookie("C2B_questions_answer", JSON.stringify(data), { expires: 7 });547}548function onSubmit(value)549{550 var res = null;551 if (value.substr(0, 1) != "{")552 {553 alert("Unknown Errorï¼");554 return;555 }556 res = $.parseJSON(value);557 switch (res.code)558 {559 case 0:560 $(".shadow-panel").show();561 window.location.reload();562 break;563 default:564 alert(res.info);565 }566}567function send_survey(){568 $(".shadow-panel").hide();569 var result;570 if ($.cookie("C2B_questions_answer") == undefined || $.cookie("C2B_questions_answer") == "null") {571 result = "";572 }573 else {574 result =$.cookie("C2B_questions_answer") ;575 }576 if(result) {577 $.post("?m=faq&a=answer", {data: JSON.stringify(JSON.parse(result))}, onSubmit);578 }579 else{580 alert("Unknown Errorï¼");581 }582}583function getNextIndex(curQuestionIndex) {584 switch (curQuestionIndex.toString()) {585 case "1":586 return nextIndex_q1();587 break;588 case "2":589 return nextIndex_q2();590 break;591 case "3":592 return nextIndex_q3();593 break;594 case "4":595 return nextIndex_q4();596 break;597 case "5":598 return nextIndex_q5();599 break;600 case "6":601 return nextIndex_q6();602 break;603 case "7":604 return nextIndex_q7();605 break;606 case "8":607 return nextIndex_q8();608 break;609 case "9":610 return nextIndex_q9();611 break;612 case "10":613 return nextIndex_q10();614 break;615 case "11":616 return nextIndex_q11();617 break;618 case "12":619 return nextIndex_q12();620 break;621 case "13":622 return nextIndex_q13();623 break;624 case "14":625 return nextIndex_q14();626 break;627 case "15":628 return nextIndex_q15();629 break;630 case "16":631 return nextIndex_q16();632 break;633 }...
Problems.ts
Source:Problems.ts
1import { Problem } from "./interfaces/Problem";2export const Problems: Array<Problem> = [3 {4 problem: "3 + 5 =",5 answer: "8",6 currentIndex: 0,7 nextIndex: 1,8 hints: ["8 ="]9 },10 {11 problem: "7 + 11 =",12 answer: "18",13 currentIndex: 1,14 nextIndex: 2,15 hints: ["18 ="]16 },17 {18 problem: "23 + 22 =",19 answer: "45",20 currentIndex: 2,21 nextIndex: 3,22 hints: ["45 ="]23 },24 {25 problem: "101 + 98 =",26 answer: "199",27 currentIndex: 3,28 nextIndex: 4,29 hints: ["199 ="]30 },31 {32 problem: "42 + 161 =",33 answer: "203",34 currentIndex: 4,35 nextIndex: 5,36 hints: ["203 ="]37 },38 {39 problem: "3 + 7 + 8 =",40 answer: "18",41 currentIndex: 5,42 nextIndex: 6,43 hints: ["10 + 8 =", "18 ="]44 },45 {46 problem: "9 + 18 + 24 =",47 answer: "51",48 currentIndex: 6,49 nextIndex: 7,50 hints: ["27 + 24 =", "51 ="]51 },52 {53 problem: "33 + 31 + 32 =",54 answer: "96",55 currentIndex: 7,56 nextIndex: 8,57 hints: ["64 + 32 =", "96 ="]58 },59 {60 problem: "77 + 13 + 2 =",61 answer: "92",62 currentIndex: 8,63 nextIndex: 9,64 hints: ["90 + 2 =", "92 ="]65 },66 {67 problem: "48 + 17 + 7 =",68 answer: "72",69 currentIndex: 9,70 nextIndex: 10,71 hints: ["65 + 7 =", "72 ="]72 },73 {74 problem: "56 + 11 + 15 =",75 answer: "82",76 currentIndex: 10,77 nextIndex: 11,78 hints: ["67 + 11 =", "82 ="]79 },80 {81 problem: "19 + 33 + 94 =",82 answer: "146",83 currentIndex: 11,84 nextIndex: 12,85 hints: ["52 + 94 =", "146 ="]86 },87 {88 problem: "21 + 16 + 38 =",89 answer: "75",90 currentIndex: 12,91 nextIndex: 13,92 hints: ["37 + 38 =", "75 ="]93 },94 {95 problem: "7 + 77 + 85 =",96 answer: "169",97 currentIndex: 13,98 nextIndex: 14,99 hints: ["84 + 84 =", "169 ="]100 },101 {102 problem: "15 + 48 + 11 =",103 answer: "74",104 currentIndex: 14,105 nextIndex: 15,106 hints: ["63 + 11 =", "74 ="]107 },108 {109 problem: "13 - 5 =",110 answer: "8",111 currentIndex: 15,112 nextIndex: 16,113 hints: ["8 ="]114 },115 {116 problem: "22 - 11 =",117 answer: "11",118 currentIndex: 16,119 nextIndex: 17,120 hints: ["11 ="]121 },122 {123 problem: "123 - 44 =",124 answer: "79",125 currentIndex: 17,126 nextIndex: 18,127 hints: ["79 ="]128 },129 {130 problem: "10 - 15 =",131 answer: "-5",132 currentIndex: 18,133 nextIndex: 19,134 hints: ["-5 ="]135 },136 {137 problem: "1001 - 76 =",138 answer: "925",139 currentIndex: 19,140 nextIndex: 20,141 hints: ["925 ="]142 },143 {144 problem: "323 - 51 =",145 answer: "272",146 currentIndex: 20,147 nextIndex: 21,148 hints: ["272 ="]149 },150 {151 problem: "117 - 19 =",152 answer: "98",153 currentIndex: 21,154 nextIndex: 22,155 hints: ["98 ="]156 },157 {158 problem: "44 - 5 - 18 =",159 answer: "21",160 currentIndex: 22,161 nextIndex: 23,162 hints: ["39 - 18 =", "21 ="]163 },164 {165 problem: "5 x 4 =",166 answer: "20",167 currentIndex: 23,168 nextIndex: 24,169 hints: ["20 ="]170 },171 {172 problem: "6 x 3 =",173 answer: "18",174 currentIndex: 24,175 nextIndex: 25,176 hints: ["18 ="]177 },178 {179 problem: "7 x 8 =",180 answer: "56",181 currentIndex: 25,182 nextIndex: 26,183 hints: ["56 ="]184 },185 {186 problem: "13 x 3 =",187 answer: "39",188 currentIndex: 26,189 nextIndex: 27,190 hints: ["39 ="]191 },192 {193 problem: "25 x 4 =",194 answer: "100",195 currentIndex: 27,196 nextIndex: 28,197 hints: ["100 ="]198 },199 {200 problem: "16 x 3 =",201 answer: "48",202 currentIndex: 28,203 nextIndex: 29,204 hints: ["48 ="]205 },206 {207 problem: "12 x 9 =",208 answer: "108",209 currentIndex: 29,210 nextIndex: 30,211 hints: ["108 ="]212 },213 {214 problem: "5 x 3 x 2 =",215 answer: "30",216 currentIndex: 30,217 nextIndex: 31,218 hints: ["(5 x 3) x 2 =", "15 x 2 =", "30 ="]219 },220 {221 problem: "6 x 8 + 3 =",222 answer: "51",223 currentIndex: 31,224 nextIndex: 32,225 hints: ["(6 x 8) + 3 =", "48 + 3 =", "51 ="]226 },227 {228 problem: "1 + 2 x 3 =",229 answer: "7",230 currentIndex: 32,231 nextIndex: 33,232 hints: ["1 + (2 x 3) =", "1 + 6 =", "7 ="]233 },234 {235 problem: "1 - 2 x 3 =",236 answer: "-5",237 currentIndex: 33,238 nextIndex: 34,239 hints: ["1 - (2 x 3) =", "1 - 6 =", "-5 ="]240 },241 {242 problem: "3 x 3 x 9 =",243 answer: "81",244 currentIndex: 34,245 nextIndex: 35,246 hints: ["(3 x 3) x 9 =", "9 x 9 =", "81 ="]247 },248 {249 problem: "7 + 8 x 2 =",250 answer: "23",251 currentIndex: 35,252 nextIndex: 36,253 hints: ["7 + (8 x 2) =", "7 + 16 =", "23 ="]254 },255 {256 problem: "11 x 3 + 15 =",257 answer: "48",258 currentIndex: 36,259 nextIndex: 37,260 hints: ["(11 x 3) + 15 =", "33 + 15 =", "48 ="]261 },262 {263 problem: "60 - 6 x 6 =",264 answer: "24",265 currentIndex: 37,266 nextIndex: 38,267 hints: ["60 - (6 x 6) =", "60 - 36 =", "24 ="]268 },269 {270 problem: "13 + 5 x 7 =",271 answer: "48",272 currentIndex: 38,273 nextIndex: 39,274 hints: ["13 + (5 x 7) =", "13 + 35 =", "48 ="]275 },276 {277 problem: "16 x 2 - 3 =",278 answer: "29",279 currentIndex: 39,280 nextIndex: 40,281 hints: ["(16 x 2) - 3 =", "32 - 3 = ", "29 ="]282 },283 {284 problem: "23 x 3 + 5 =",285 answer: "74",286 currentIndex: 40,287 nextIndex: 41,288 hints: ["(23 x 3) + 5 =", "69 + 3 =", "74 ="]289 },290 {291 problem: "21 x 4 + 7 =",292 answer: "91",293 currentIndex: 41,294 nextIndex: 42,295 hints: ["(21 x 4) + 7 =", "84 + 7 =", "91 ="]296 },297 {298 problem: "33 - 3 x 10 =",299 answer: "3",300 currentIndex: 42,301 nextIndex: 43,302 hints: ["33 - (3 x 10) =", "33 - 30 =", "3 ="]303 },304 {305 problem: "5 + 3 x 11 =",306 answer: "38",307 currentIndex: 43,308 nextIndex: 44,309 hints: ["5 + (3 x 11) =", "5 + 33 ) =", "38 ="]310 },311 {312 problem: "7 x 7 x 2 =",313 answer: "98",314 currentIndex: 44,315 nextIndex: 45,316 hints: ["(7 x 7) x 2 =", "49 x 2 =", "98 ="]317 },318 {319 problem: "3 - 2 x 8 + 3 =",320 answer: "-10",321 currentIndex: 45,322 nextIndex: 46,323 hints: ["3 - (2 x 8) + 3 =", "3 - 16 + 3 =", "3 - 13 =", "-10 ="]324 },325 {326 problem: "7 + 11 x 4 + 5 =",327 answer: "56",328 currentIndex: 46,329 nextIndex: 47,330 hints: ["7 + (11 x 4) + 5 =", "7 + 44 + 5 =", "51 + 5 =", "56 ="]331 },332 {333 problem: "58 - 8 x 7 =",334 answer: "2",335 currentIndex: 47,336 nextIndex: 48,337 hints: ["58 - (8 x 7) =", "58 - 56 =", "2 ="]338 },339 {340 problem: "15 / 3 =",341 answer: "5",342 currentIndex: 48,343 nextIndex: 49,344 hints: ["5 ="]345 },346 {347 problem: "25 / 5 =",348 answer: "5",349 currentIndex: 49,350 nextIndex: 50,351 hints: ["5 ="]352 },353 {354 problem: "6 + 6 / 3 =",355 answer: "8",356 currentIndex: 50,357 nextIndex: 51,358 hints: ["6 + (6 / 3) =", "6 + 2 =", "8 ="]359 },360 {361 problem: "17 - 8 / 4 =",362 answer: "15",363 currentIndex: 51,364 nextIndex: 52,365 hints: ["17 - (8 / 4) =", "17 - 2 =", "15 ="]366 },367 {368 problem: "3 x 8 / 4 =",369 answer: "6",370 currentIndex: 52,371 nextIndex: 53,372 hints: ["(3 x 8) / 4 =", "24 / 4 =", "6 ="]373 },374 {375 problem: "5 x 9 / 3 =",376 answer: "15",377 currentIndex: 53,378 nextIndex: 54,379 hints: ["(5 x 9) / 3 =", "45 / 3 =", "15 ="]380 },381 {382 problem: "11 + 9 / 3 =",383 answer: "14",384 currentIndex: 54,385 nextIndex: 55,386 hints: ["11 + (9 / 3) =", "11 + 3 =", "14 ="]387 },388 {389 problem: "22 / 2 + 15 =",390 answer: "26",391 currentIndex: 55,392 nextIndex: 56,393 hints: ["(22 / 2) + 15 =", "11 + 15 =", "26 ="]394 },395 {396 problem: "43 + 5 x 5 =",397 answer: "68",398 currentIndex: 56,399 nextIndex: 57,400 hints: ["43 + (5 x 5) =", "43 + 25 =", "68 ="]401 },402 {403 problem: "1 x 2 + 3 - 4 =",404 answer: "1",405 currentIndex: 57,406 nextIndex: 58,407 hints: ["(1 x 2) + 3 - 4 =", "2 + 3 - 4 =", "5 - 4 =", "1 ="]408 },409 {410 problem: "4 + 5 x 6 - 7 =",411 answer: "27",412 currentIndex: 58,413 nextIndex: 59,414 hints: ["4 + (5 x 6) - 7 =", "4 + 30 - 7 =", "34 - 7 =", "27 ="]415 },416 {417 problem: "2 + 2 x 2 / 2 =",418 answer: "4",419 currentIndex: 59,420 nextIndex: 60,421 hints: ["2 + (2 x 2) / 2 =", "2 + 4 / 2 =", "2 + (4 / 2) =", "2 + 2 =", "4 ="]422 },423 {424 problem: "3 x 4 x 5 - 10 =",425 answer: "50",426 currentIndex: 60,427 nextIndex: 61,428 hints: ["(3 x 4 x 5) - 10 =", "(12 x 5) - 10 =", "60 - 10 =", "50 ="]429 },430 {431 problem: "10 - 1 x 8 + 2 =",432 answer: "4",433 currentIndex: 61,434 nextIndex: 62,435 hints: ["10 - (1 x 8) + 2 =", "10 - 8 + 2 =", "2 + 2 =", "4 ="]436 },437 {438 problem: "13 x 3 + 5 - 2 =",439 answer: "42",440 currentIndex: 62,441 nextIndex: 63,442 hints: ["(13 x 3) + 5 - 2 =", "39 + 5 - 2 =", "44 - 2 =", "42 ="]443 },444 {445 problem: "7 + 7 x 4 / 2 =",446 answer: "21",447 currentIndex: 63,448 nextIndex: 64,449 hints: ["7 + (7 x 4) / 2 =", "7 + 28 / 2 =", "7 + (28 / 2) =", "7 + 14 =", "21 ="]450 },451 {452 problem: "17 - 6 x 3 + 1 =",453 answer: "0",454 currentIndex: 64,455 nextIndex: 65,456 hints: ["17 - (6 x 3) + 1 =", "17 - 18 + 1 =", "-1 + 1 =", "0 ="]457 },458 {459 problem: "2 - 8 x 4 =",460 answer: "-30",461 currentIndex: 65,462 nextIndex: 66,463 hints: ["2 - (8 x 4) = ", "2 - 32 =", "-30 ="]464 },465 {466 problem: "6 + 6 x 6 / 6 =",467 answer: "12",468 currentIndex: 66,469 nextIndex: 67,470 hints: ["6 + (6 x 6) / 6 =", "6 + 36 / 6 =", "6 + (36 / 6) =", "6 + 6 =", "12 ="]471 },472 {473 problem: "5 / 5 + 8 - 8 =",474 answer: "1",475 currentIndex: 67,476 nextIndex: 68,477 hints: ["(5 / 5) + 8 - 8 =", "1 + 8 - 8 =", "9 - 8 =", "1"]478 },479 {480 problem: "23 + 7 x 3 =",481 answer: "44",482 currentIndex: 68,483 nextIndex: 69,484 hints: ["23 + (7 x 3) =", "23 + 21 =", "44 ="]485 },486 {487 problem: "44 - 28 x 2 =",488 answer: "-12",489 currentIndex: 69,490 nextIndex: 70,491 hints: ["44 - (28 x 2) =", "44 - 56 =", "-12 ="]492 },493 {494 problem: "-12 + 6 x 3",495 answer: "6",496 currentIndex: 70,497 nextIndex: 71,498 hints: ["-12 + (6 x 3) =", "-12 + 18 =", "6 ="]499 },500 {501 problem: "-1 + 2 x 3 =",502 answer: "5",503 currentIndex: 71,504 nextIndex: 72,505 hints: ["-1 + (2 x 3) =", "-1 + 6 =", "5 ="]506 },507 {508 problem: "8 x -2 + 15 =",509 answer: "-1",510 currentIndex: 72,511 nextIndex: 73,512 hints: ["(8 x -2) + 15 =", "-16 + 15 =", "-1 ="]513 },514 {515 problem: "16 x 3 - 8 + 5 =",516 answer: "45",517 currentIndex: 73,518 nextIndex: 74,519 hints: ["(16 x 3) - 8 + 5 =", "48 - 8 + 5 =", "40 + 5 =", "45 ="]520 },521 {522 problem: "5 + 5 x 2 - 8 =",523 answer: "7",524 currentIndex: 74,525 nextIndex: 75,526 hints: ["5 + (5 x 2) - 8 =", "5 + 10 - 8 =", "15 - 8 =", "7 ="]527 },528 {529 problem: "13 + 22 x 3 =",530 answer: "79",531 currentIndex: 75,532 nextIndex: 76,533 hints: ["13 + (22 x 3) =", "13 + 66 =", "79 ="]534 },535 {536 problem: "60 - 37 x 2 =",537 answer: "-14",538 currentIndex: 76,539 nextIndex: 77,540 hints: ["60 - (37 x 2) =", "60 - 74 =", "-14 ="]541 },542 {543 problem: "6 + 66 / 2 =",544 answer: "39",545 currentIndex: 77,546 nextIndex: 78,547 hints: ["6 + (66 / 2) =", "6 + 33 =", "39 ="]548 },549 {550 problem: "15 - 3 x 8 =",551 answer: "-9 =",552 currentIndex: 78,553 nextIndex: 79,554 hints: ["15 - (3 x 8) =", "15 - 24 =", "-9 ="]555 },556 {557 problem: "13 - 7 x 11 =",558 answer: "-64",559 currentIndex: 79,560 nextIndex: 80,561 hints: ["13 - (7 x 11) =", "13 - 77 =", "-64 ="]562 },563 {564 problem: "5 + 8 + 12 x 4 =",565 answer: "61",566 currentIndex: 80,567 nextIndex: 81,568 hints: ["5 + 8 + (12 x 4) =", "5 + 8 + 48 =", "13 + 48 =", "61 ="]569 },570 {571 problem: "63 - 11 - 12 =",572 answer: "40",573 currentIndex: 81,574 nextIndex: 82,575 hints: ["52 - 12 =", "40 ="]576 },577 {578 problem: "70 - 13 - 42 =",579 answer: "15",580 currentIndex: 82,581 nextIndex: 83,582 hints: ["57 - 42 =", "15 ="]583 },584 {585 problem: "77 - 6 - 38 =",586 answer: "33",587 currentIndex: 83,588 nextIndex: 84,589 hints: ["71 - 38 =", "33 ="]590 },591 {592 problem: "121 - 41 - 3 =",593 answer: "77",594 currentIndex: 84,595 nextIndex: 85,596 hints: ["80 - 3 =", "77 ="]597 },598 {599 problem: "202 - 22 - 80 =",600 answer: "100",601 currentIndex: 85,602 nextIndex: 86,603 hints: ["180 - 80 =", "100 ="]604 },605 {606 problem: "98 - 59 - 5 =",607 answer: "34",608 currentIndex: 86,609 nextIndex: 87,610 hints: ["39 - 5 =", "34 ="]611 },612 {613 problem: "54 - 35 - 18 =",614 answer: "1",615 currentIndex: 87,616 nextIndex: 88,617 hints: ["19 - 18 =", "1 ="]618 },619 {620 problem: "154 - 67 - 2 =",621 answer: "85",622 currentIndex: 88,623 nextIndex: 89,624 hints: ["87 - 2 =", "85 ="]625 },626 {627 problem: "167 - 98 - 69 =",628 answer: "0",629 currentIndex: 89,630 nextIndex: 90,631 hints: ["69 - 69 =", "0 ="]632 },633 {634 problem: "333 - 231 - 7 =",635 answer: "95",636 currentIndex: 90,637 nextIndex: 91,638 hints: ["102 - 7 =", "95 ="]639 },640 {641 problem: "45 - 48 x 3 - 2 =",642 answer: "-101",643 currentIndex: 91,644 nextIndex: 92,645 hints: ["45 - (48 x 3) - 2 =", "45 - 144 - 2", "-99 - 2 =", "-101 ="]646 },647 {648 problem: "152 - 63 x 3 =",649 answer: "-37",650 currentIndex: 92,651 nextIndex: 93,652 hints: ["152 - (63 x 3) =", "152 - 189 =", "-37 ="]653 },654 {655 problem: "2 x 2 x 2 / 2 x 2 + 2 =",656 answer: "10",657 currentIndex: 93,658 nextIndex: 94,659 hints: ["(2 x 2 x 2) / 2 x 2 + 2 =", "8 / 2 x 2 + 2 =", "(8 / 2) x 2 + 2 =", "4 x 2 + 2 =", "(4 x 2) + 2 =", "8 + 2 =", "10 ="]660 },661 {662 problem: "3 x 3 x -3 + 3 x 3 =",663 answer: "-18",664 currentIndex: 94,665 nextIndex: 95,666 hints: ["(3 x 3 x -3) + 3 x 3 =", "-27 + 3 x 3 =", "-27 + (3 x 3) =", "-27 + 9 =", "-18 ="]667 },668 {669 problem: "77 x 3 - 8 + 5 =",670 answer: "228",671 currentIndex: 95,672 nextIndex: 96,673 hints: ["(77 x 3) - 8 + 5 =", "231 - 8 + 5 =", "223 + 5 ="]674 },675 {676 problem: "4 x 4 / 4 x 4 + 4 =",677 answer: "20",678 currentIndex: 96,679 nextIndex: 97,680 hints: ["(4 x 4) / 4 x 4 + 4 =", "16 / 4 x 4 + 4 =", "(16 / 4) x 4 + 4 =", "4 x 4 + 4 =", "(4 x 4) + 4 =", "16 + 4 =", "20 ="]681 },682 {683 problem: "15 x 3 + 40 x 3 =",684 answer: "165",685 currentIndex: 97,686 nextIndex: 98,687 hints: ["(15 x 3) + 40 x 3 =", "45 + 40 x 3 =", "45 + (40 x 3) =", "45 + 120 =", "165 ="]688 },689 {690 problem: "92 - 45 x 3 + 8 =",691 answer: "-35",692 currentIndex: 98,693 nextIndex: 99,694 hints: ["92 - (45 x 3) + 8 =", "92 - 135 + 8 =", "-43 + 8 =", "-35 ="]695 },696 {697 problem: "7 x 7 x 2 + 5 - 2 + 2 =",698 answer: "44",699 currentIndex: 99,700 nextIndex: -1,701 hints: ["(7 x 7 x 2) + 5 - 2 + 2", "(49 x 2) + 5 - 2 + 2 =", "98 + 5 - 2 + 2 =", "103 - 2 + 2 =", "101 + 2 =", "103 ="]702 },...
mergeSort.js
Source:mergeSort.js
1export function mergeSortAnimations(array) {2 if(array.length < 2) return array3 const animations = [];4 const elements = [];5 for(let i = 0; i < array.length; i++) {6 let element = {value: array[i], index: i}7 elements.push(element);8 }9 mergeSort(array, elements, animations);10 return animations;11}12function mergeSort(array, elements, animations) {13 //check if array can be split 14 if(elements.length < 2) return elements; ;15 //get middle index16 const middle = Math.floor(elements.length/ 2);17 //split temp array down into left and right components18 let left = elements.slice(0, middle);19 let right = elements.slice(middle);20 //recursively continue spliting arrays21 return mergeHelper(mergeSort(array, left, animations), mergeSort(array, right, animations), animations, array);22}23function mergeHelper(left, right, animations, array) {24 let sortedArray = [];25 let rangeOfIndices = [];26 let start = left[0].index;27 let end = right[right.length-1].index;28 let finalMerge = ((left.length + right.length) === array.length);29 for(let i = start; i <= end; i++){30 rangeOfIndices.push(i);31 }32 while(left.length && right.length) {33 let nextIndex = rangeOfIndices.shift();34 let highlightElements = {35 values: [left[0].value, right[0].value],36 indices: [nextIndex, right[0].index],37 swap: false,38 color: 'highlight'39 }40 let revertElements = {41 values: [left[0].value, right[0].value],42 index: [right[0].index],43 swap: false,44 color: 'revert'45 }46 animations.push(highlightElements);47 animations.push(revertElements);48 if(finalMerge) {49 if(left[0].value <= right[0].value) {50 let element = {value: left[0].value, index: nextIndex, color: 'color'};51 let alteredElements = {value: left[0].value, index: nextIndex, swap: false, color: 'correct'};52 //let revertElements = {type: 'single', value: left[0].value, index: nextIndex, swap: false, color: 'revert'};53 if(nextIndex === left[0].index) element.swap = false;54 else element.swap = true;55 left.shift();56 animations.push(element);57 animations.push(alteredElements);58 //animations.push(revertElements);59 sortedArray.push(element);60 }61 else { //(right[0].value < left[0].value)62 let element = {value: right[0].value, index: nextIndex, color: 'color'};63 let alteredElements = {value: right[0].value, index: nextIndex, swap: false, color: 'correct'};64 //let revertElements = {type: 'single', value: right[0].value, index: nextIndex, swap: false, color: 'revert'};65 if(nextIndex === right[0].index) element.swap = false;66 else element.swap = true;67 right.shift();68 animations.push(element);69 animations.push(alteredElements);70 //animations.push(revertElements);71 sortedArray.push(element);72 }73 }74 else {75 if(left[0].value <= right[0].value) {76 let element = {value: left[0].value, index: nextIndex, color: 'color'};77 let alteredElements = {value: left[0].value, index: nextIndex, swap: false, color: 'altered'};78 let revertElements = {type: 'single', value: left[0].value, index: nextIndex, swap: false, color: 'revert'};79 if(nextIndex === left[0].index) element.swap = false;80 else element.swap = true;81 left.shift();82 animations.push(element);83 animations.push(alteredElements);84 animations.push(revertElements);85 sortedArray.push(element);86 }87 else { //(right[0].value < left[0].value)88 let element = {89 value: right[0].value,90 index: nextIndex,91 color: 'color'92 };93 let alteredElements = {value: right[0].value, index: nextIndex, swap: false, color: 'altered'};94 let revertElements = {type: 'single', value: right[0].value, index: nextIndex, swap: false, color: 'revert'};95 if(nextIndex === right[0].index) element.swap = false;96 else element.swap = true;97 right.shift();98 animations.push(element);99 animations.push(alteredElements);100 animations.push(revertElements);101 sortedArray.push(element);102 }103 }104 /*105 let revertElements = {106 type: 'double',107 values: [left[0].value, right[0].value],108 indices: [nextIndex, right[0].index],109 swap: false,110 color: 'revert'111 }112 animations.push(revertElements);113 114 if(left[0].value <= right[0].value) {115 let element = {value: left[0].value, index: nextIndex, color: 'color'};116 let alteredElements = {value: left[0].value, index: nextIndex, swap: false, color: 'altered'};117 let revertElements = {type: 'single', value: left[0].value, index: nextIndex, swap: false, color: 'revert'};118 if(nextIndex === left[0].index) element.swap = false;119 else element.swap = true;120 left.shift();121 animations.push(element);122 animations.push(alteredElements);123 animations.push(revertElements);124 sortedArray.push(element);125 }126 else { //(right[0].value < left[0].value)127 let element = {128 value: right[0].value,129 index: nextIndex,130 color: 'color'131 };132 let alteredElements = {value: right[0].value, index: nextIndex, swap: false, color: 'altered'};133 let revertElements = {type: 'single', value: right[0].value, index: nextIndex, swap: false, color: 'revert'};134 if(nextIndex === right[0].index) element.swap = false;135 else element.swap = true;136 right.shift();137 animations.push(element);138 animations.push(alteredElements);139 animations.push(revertElements);140 sortedArray.push(element);141 }142 */143 }144 145 //while elements still exist in left and right146 while(left.length) {147 let nextIndex = rangeOfIndices.shift();148 let element = {149 value: left[0].value,150 index: nextIndex,151 color: 'color'152 };153 if(finalMerge) {154 let alteredElements = {value: left[0].value, index: nextIndex, swap: false, color: 'correct'};155 //let revertElements = {type: 'single', value: left[0].value, index: nextIndex, swap: false, color: 'revert'};156 if(nextIndex === left[0].index) element.swap = false;157 else element.swap = true;158 left.shift();159 animations.push(element);160 animations.push(alteredElements);161 //animations.push(revertElements);162 }163 else {164 let alteredElements = {value: left[0].value, index: nextIndex, swap: false, color: 'altered'};165 let revertElements = {type: 'single', value: left[0].value, index: nextIndex, swap: false, color: 'revert'};166 if(nextIndex === left[0].index) element.swap = false;167 else element.swap = true;168 left.shift();169 animations.push(element);170 animations.push(alteredElements);171 animations.push(revertElements);172 }173 sortedArray.push(element);174 }175 while(right.length){176 let nextIndex = rangeOfIndices.shift();177 let element = {178 value: right[0].value,179 index: nextIndex,180 color: 'color'181 };182 if(finalMerge) {183 let alteredElements = {value: right[0].value, index: nextIndex, swap: false, color: 'correct'};184 //let revertElements = {type: 'single', value: right[0].value, index: nextIndex, swap: false, color: 'revert'};185 if(nextIndex === right[0].index) element.swap = false;186 else element.swap = true;187 right.shift();188 animations.push(element);189 animations.push(alteredElements);190 //animations.push(revertElements);191 }192 else {193 let alteredElements = {value: right[0].value, index: nextIndex, swap: false, color: 'altered'};194 let revertElements = {type: 'single', value: right[0].value, index: nextIndex, swap: false, color: 'revert'};195 if(nextIndex === right[0].index) element.swap = false;196 else element.swap = true;197 right.shift();198 animations.push(element);199 animations.push(alteredElements);200 animations.push(revertElements);201 }202 sortedArray.push(element);203 }204 return sortedArray;...
Using AI Code Generation
1import React from 'react';2import { storiesOf } from '@storybook/react';3import { withInfo } from '@storybook/addon-info';4import { withKnobs } from '@storybook/addon-knobs';5import { action } from '@storybook/addon-actions';6import { linkTo } from '@storybook/addon-links';7import { withNotes } from '@storybook/addon-notes';8import { withA11y } from '@storybook/addon-a11y';9import { withViewport } from '@storybook/addon-viewport';10import { withConsole } from '@storybook/addon-console';11import { withOptions } from '@storybook/addon-options';12import { withTests } from '@storybook/addon-jest';13import { withBackgrounds } from '@storybook/addon-backgrounds';14import { withCsf } from '@storybook/addon-csf';15import { withCssResources } from '@storybook/addon-cssresources';16import { withGraphQL } from '@storybook/addon-graphql';17import { withHeadings } from '@storybook/addon-headings';18import { withHTML } from '@storybook/addon-html';19import { withI18n } from '@storybook/addon-i18n';20import { withInfoAddon } from '@storybook/addon-info';21import { withJest } from '@storybook/addon-jest';22import { withLinks } from '@storybook/addon-links';23import { withLiveEdit } from '@storybook/addon-live-edit';24import { withLiveEditScope } from '@storybook/addon-live-edit';25import { withPerformance } from '@storybook/addon-performance';26import { withPropsCombinations } from '@storybook/addon-props-combinations';27import { withPropsTable } from '@storybook/addon-props-table';28import { withReadme } from '@storybook/addon-readme';29import { withSmartKnobs } from '@storybook/addon-smart-knobs';30import { withStoriesPanel } from '@storybook/addon-stories-panel';31import { withStorySource } from '@storybook/addon-storysource';32import { withStoryshots } from '@storybook/addon-storyshots';33import { withStoryshotsOptions } from '@storybook/addon-storyshots';34import { withTestsOptions } from '@storybook/addon-jest';35import { withThemes } from '@storybook/addon-themes';36import { withToolkit } from '@storybook/addon-toolkit';37import { withTranslation } from '@storybook/addon-translation';38import { with
Using AI Code Generation
1import { storiesOf } from '@storybook/react';2import { nextIndex } from 'storybook-root';3storiesOf('NextIndex', module)4 .add('NextIndex', () => {5 return <div>{nextIndex()}</div>;6 });7export const nextIndex = () => {8 const { storyStore } = require('@storybook/client-api');9 const stories = storyStore.raw();10 const story = stories[0];11 const { kind, story: storyName } = story;12 return storyStore.storyIndex(kind, storyName) + 1;13};14import { addDecorator } from '@storybook/react';15import { withInfo } from '@storybook/addon-info';16import { withKnobs } from '@storybook/addon-knobs';17import { withRoot } from 'storybook-root';18addDecorator(withInfo);19addDecorator(withKnobs);20addDecorator(withRoot);
Using AI Code Generation
1import {nextIndex} from 'storybook-root';2nextIndex();3export const nextIndex = () => {4};5export const setIndex = (index) => {6};7export const getIndex = () => {8};9export const resetIndex = () => {10};11const storybookRoot = {12};13export default storybookRoot;
Using AI Code Generation
1import { nextIndex } from 'storybook-root';2const next = nextIndex(1, 2);3export const nextIndex = (currentIndex, lastIndex) => {4 if (currentIndex === lastIndex) {5 return 0;6 }7 return currentIndex + 1;8};
Using AI Code Generation
1import { nextIndex } from 'storybook-root'2const nextIndex = nextIndex();3console.log(nextIndex);4import { prevIndex } from 'storybook-root'5const prevIndex = prevIndex();6console.log(prevIndex);7import { gotoIndex } from 'storybook-root'8const gotoIndex = gotoIndex(2);9console.log(gotoIndex);10import { gotoId } from 'storybook-root'11const gotoId = gotoId('test-story');12console.log(gotoId);13import { gotoPath } from 'storybook-root'14const gotoPath = gotoPath('/test-story');15console.log(gotoPath);16import { goto } from 'storybook-root'17const goto = goto('test-story');18console.log(goto);19import { selectStory } from 'storybook-root'20const selectStory = selectStory('test-story');21console.log(selectStory);22import { selectKind } from 'storybook-root'23const selectKind = selectKind('test-story');24console.log(selectKind);25import { selectStory } from 'storybook-root'26const selectStory = selectStory('test-story');27console.log(selectStory);28import { selectStory } from 'storybook-root'29const selectStory = selectStory('test-story');30console.log(selectStory);31import { selectStory } from '
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!