0067【Edabit ★☆☆☆☆☆】【英寸转英尺】Inches to Feet
language_fundamentals
math
Instructions
Create a function that accepts a measurement value in inches and returns the equivalent of the measurement value in feet.
Examples
javascript">inchesToFeet(324) // 27
inchesToFeet(12) // 1
inchesToFeet(36) // 3
Notes
- If inches are under 12, return
0
. - 12 inches = 1 foot.
Solutions
javascript">function inchesToFeet(inches) {
return Math.floor(inches/12)
}
TestCases
javascript">let Test = (function(){
return {
assertEquals:function(actual,expected){
if(actual !== expected){
let errorMsg = `actual is ${actual},${expected} is expected`;
throw new Error(errorMsg);
}
},
assertSimilar:function(actual,expected){
if(actual.length != expected.length){
throw new Error(`length is not equals, ${actual},${expected}`);
}
for(let a of actual){
if(!expected.includes(a)){
throw new Error(`missing ${a}`);
}
}
}
}
})();
Test.assertEquals(inchesToFeet(12), 1)
Test.assertEquals(inchesToFeet(360), 30)
Test.assertEquals(inchesToFeet(3612), 301)
Test.assertEquals(inchesToFeet(324), 27)
Test.assertEquals(inchesToFeet(3012), 251)
Test.assertEquals(inchesToFeet(11), 0)