You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functioncountSmallerThan(numbers,cutoff){letcountSoFar=0;for(letnumberofnumbers){if(number<cutoff){countSoFar=countSoFar+1;}}returncountSoFar;}letpile=[1,15,-10,3,15,88];letcountBelow10=countSmallerThan(pile,10);letcountBelow0=countSmallerThan(pile,0);letcountBelow50=countSmallerThan(pile,50);console.log(`There are #{countBelow10} numbers smaller than 10 in the list.`);console.log(`There are #{countBelow0} numbers smaller than 0 in the list.`);console.log(`There are #{countBelow50} numbers smaller than 50 in the list.`);
Python
defcount_smaller_than(numbers,cutoff)count_so_far=0fornumberinnumbers:
ifnumber<cutoff :
count_so_far=count_so_far+1returncount_so_farpile=[1,15,-10,3,15,88]count_below_10=count_smaller_than(pile,10)count_below_0=count_smaller_than(pile,0)count_below_50=count_smaller_than(pile,50)print(f'There are {count_below_10} numbers smaller than 10 in the list.')print(f'There are {count_below_0} numbers smaller than 0 in the list.')print(f'There are {count_below_50} numbers smaller than 50 in the list.')
Ruby
defcount_smaller_than(numbers,cutoff)count_so_far=0numbers.eachdo|number|if(number<cutoff)count_so_far=count_so_far+1endendreturncount_so_farendpile=[1,15,-10,3,15,88]count_below_10=count_smaller_than(pile,10)count_below_0=count_smaller_than(pile,0)count_below_50=count_smaller_than(pile,50)puts("There are #{count_below_10} numbers smaller than 10 in the list.")puts("There are #{count_below_0} numbers smaller than 0 in the list.")puts("There are #{count_below_50} numbers smaller than 50 in the list.")