Great work today! Now we are almost done with Basic Algorithm Scripting and can soon go on to do Object Oriented Programming. How exciting!
Quick reminder about “homework” for the next session!
Tomorrow we’ll actually start with Object Oriented Programming. So, please try to complete the section about Basic Algorithm Scripting:
Remember to take it easy once in a while as well though!
Don’t hesitate to seek help in the js-help channel or on the forum! We are all in this together!
During the Telephone Number Validator video, there was a question about “Where Do I Belong?” from Basic Algorithm Scripting. A simpler approach to this problem is to note that you don’t actually need to sort the given array. All you need to do is count how many numbers of the given array are lower than the given number, and that gives you exactly the index of where the number would go after sorting:
function getIndexToIns(arr, num) {
let index = 0;
for (let i of arr) {
if (num > i) {
index++;
}
}
return index;
}