We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
functionwhatFlavors(cost,money){// Write your code herefor(leti=0;i<cost.length;i++){constflavor1=cost[i];if(flavor1<money){// only check indexes after the current one (i)constidxFlavor2=cost.indexOf(money-flavor1,i+1);// check if "corresponding" price exists, if true: print and exitif(idxFlavor2>i){console.log(i+1+' '+(idxFlavor2+1));// we done, loop can be abortedreturn;}}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
JS - only using array