diff --git a/challenges/javascript/minutes-into-string.js b/challenges/javascript/minutes-into-string.js index 11e04de..dac2d9a 100644 --- a/challenges/javascript/minutes-into-string.js +++ b/challenges/javascript/minutes-into-string.js @@ -1,2 +1,33 @@ // 1441 minutes into " 1 day and 1 minute " -// strip away any zeros i.e. no "0 days 4 hours 1 min" or " 1 day 12 hours 0 minutes" \ No newline at end of file +// strip away any zeros i.e. no "0 days 4 hours 1 min" or " 1 day 12 hours 0 minutes" + +// @RealWeeks solution (his was way better than mine) + +let findTime = (t) => { + let display = []; + let totalHours = Math.floor(t / 60); + let totalDays = Math.floor(totalHours / 24); + let hoursRemain = totalHours - totalDays * 24; + let minRemain = t % 60 === 0 ? t : t % 60; // log at end + if (totalHours >= 24) { + let label = totalDays > 1 ? 'Days' : "Day" + display.push(totalDays, label) + } + if (hoursRemain >= 1) { + let label = totalHours > 1 ? 'Hours' : "Hour" + display.push(hoursRemain, label) + } + if (minRemain >= 1) { + let label = minRemain > 1 ? 'Minutes' : "Minute" + display.push(minRemain, label) + } + display = display.join(' ') + console.log(display) +}; + +//works 👍 +// findTime(5020) + +// interpolation issues +findTime(1441) +findTime(3299) diff --git a/mock-questions/brainteasers.md b/mock-questions/brainteasers.md index 2d2554c..302516f 100644 --- a/mock-questions/brainteasers.md +++ b/mock-questions/brainteasers.md @@ -19,4 +19,27 @@ answer: http://www.newton.dep.anl.gov/askasci/phy99/phy99xx1.htm I was asked to develop a marketing plan for packaged ice to native Alaskans. It’s like this. Sanitary manhole covers are usually round (and solid, i.e. VERY heavy) but Storm sewer manhole and Inlet covers are usually square or rectangular grates which let water in. The deciding factor is where they are placed relative to the curb line. All covers are actually installed on a concrete generic ‘Mexican Hat’ structure which can be centered or offset to one side. The structure fits on the round concrete casting (5’ – 8” diameter) and can be made to accept any solid or grated casting. If this part of the world, where river flooding is fairly common, Sanitary manholes and lift stations are either raised above potential flood limits if possible or sealed and bolted shut, making them much more difficult to open. It’s also a very good idea to vent Sanitary manholes and lift station with a portable fan to avoid being overcome by methane and other gasses trapped in them.” -http://www.sellsbrothers.com/fun/msiview/default.aspx?content=question.htm +http://www.sellsbrothers.com/fun/msiview/default.aspx?content=question.html + + +_Two people are each stuck on their own island, connected by a ferryman with a lockable box. Each person has their own lock and key, but can't send the key along with the box. One person wants to send the other a diamond, but it must be placed into the box and locked or it will be stolen by the ferryman. How do you send the diamond without the ferryman stealing it?_ + +Wrong but good answer: +1) person A sends key only in a unlocked box to person B. +2) person B sends key only in a unlocked box to person A. +3) 3rd trip person A puts diamonds in the box snaps the lock their holding closed. (At this point owner of the lock can't open the lock. Ensure all contents are in the box before engaging lock.) +4) once the lock box arrives to person B, they can use the key provided on the trip before to open and stare at the contents, And realizes he can pay the ferryman to give him/her ride off the island. Then place a thank you note in the box and close with lock initially held by person B and which now person A has the key. + +Option B for #4 step) send a thank you note and lock with which the diamonds were so cleverly send to you sealed with. ;) + +*** Now follow up question would be, how to ensure the ferryman didn't copy the keys during the first transfer of keys? + Answer) well, I guess you could have exchanged open locks and not the keys between the two people, and if he could copy a lock on a boat - the ferryman should be looking into more rewarding currier. + +But why do they care about diamonds when their stuck on an island, not stranded just stuck - pay the ferryman. There is always a man in the middle, know what to trust and what not to. Focusing on security when you may have bigger problems is useless. + +Real Answer: + +Step 1: The person with the diamond, puts it in the box, locks it with his lock (Let's say Lock1). The ferryman takes it across. +Step 2: Person 2 locks the box again with his lock (Lock2) Sends it back with the ferryman. +Step 3 : Person 1 unlocks Lock1. Sends it back. +Step 4 : Person 2 unlocks Lock 2 and retrieves the diamond. diff --git a/mock-questions/buckets.md b/mock-questions/buckets.md index a748cbd..39743a3 100644 --- a/mock-questions/buckets.md +++ b/mock-questions/buckets.md @@ -1,3 +1,25 @@ You have two buckets. One holds exactly five gallons and the other three gallons. How can you measure exactly four gallons of water into the five gallon bucket? Assume you have an unlimited supply of water and that there are no measurement markings of any kind on the buckets. + + +# SOLUTION + + +1. Fill the 3-gallon bucket. +1. Pour the 3 gallons of water into the 5-gallon bucket +1. Fill the 3-gallon bucket again. +1. Fill up the 5-gallon bucket with the 3-gallon bucket, leaving you with 1 gallon left in the 3-gallon bucket. +1. Empty out the 5-gallon bucket. +1. Pour the remaining 1 gallon of water from the 3-gallon bucket into the 5-gallon bucket. +1. Fill the 3-gallon bucket. +1. Pour the 3 gallons of water from the 3-gallon bucket into the 5-gallon bucket leaving you with 4 gallons of water in the 5-gallon bucket. + + +### Alternate solution: + +1. Fill up the 5 gallon bucket +1. Pour it into 3 gallon bucket, leaving 2 gallons +1. Empty out the 3 gallon bucket +1. Pour the 2 gallons in the 5 gallon bucket into the 3 gallon bucket +1. Fill up the 5 gallon bucket and pour it into the 3 gallon bucket until it’s full, leaving 4 gallons in the 5 gallon bucket. \ No newline at end of file diff --git a/mock-questions/print1-100.js b/mock-questions/print1-100.js index 786c6c7..f0e9ed3 100644 --- a/mock-questions/print1-100.js +++ b/mock-questions/print1-100.js @@ -2,19 +2,29 @@ let i - for (i=100; i > 0; i--) - { - // produce the code that will print out 1 to 100 inclusively. - // console.log(101-i) +for (i = 100; i > 0; i--) { + // produce the code that will print out 1 to 100 inclusively. + // console.log(101-i) +} - } +let i -let i +for (i = 100; i > 0; i--) { + //produce the code that will print out 1 to 100 inclusively. -for (i=100; i > 0; i--) { -//produce the code that will print out 1 to 100 inclusively. + console.log(101 - i) +} -console.log(101-i) +const hundo = function() { + for (let i = 0; i < 101; i++) { + console.log(i) + } } +const hundo = function() { + for (let i = 100; i > 0; i--) { + console.log(101 - i) + } +} +hundo() diff --git a/mock-questions/two-candles.md b/mock-questions/two-candles.md index 54c51b1..9357bee 100644 --- a/mock-questions/two-candles.md +++ b/mock-questions/two-candles.md @@ -1 +1,15 @@ You are given two ropes and a lighter. This is the only equipment you can use. You are told that each of the two ropes has the following property: if you light one end of the rope, it will take exactly one hour to burn all the way to the other end. But it doesn’t have to burn at a uniform rate. In other words, half the rope may burn in the first five minutes, and then the other half would take 55 minutes. The rate at which the two ropes burn is not necessarily the same, so the second rope will also take an hour to burn from one end to the other, but may do it at some varying rate, which is not necessarily the same as the one for the first rope. Now you are asked to measure a period of 45 minutes. How will you do it? + + + + +# ANSWER: + + + +1. Light both ends of rope A and one end of rope B. +1. After 30 minutes, rope A will be completely burned up and there will be 30 minutes of rope B left. +1. Light the other end of rope B; it will burn up in 15 minutes. +1. Total time elapsed since starting the ropes on fire: 45 minutes. + +