Skip to content

Instantly share code, notes, and snippets.

@JimDennis
Forked from anonymous/bignums.ps
Last active July 9, 2017 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JimDennis/312181e8f804af9fa77b5ce2d82b885f to your computer and use it in GitHub Desktop.
Save JimDennis/312181e8f804af9fa77b5ce2d82b885f to your computer and use it in GitHub Desktop.
Sample JS Code for bigNums Exercise
/*
7. Iterate over the "bigNums" array.
If any number is less than 10, replace it with "x".
Return "bigNums"
HINT: You will need to "loop" over the array and check "if" the numbers are "less than" 10
Answer: This function should return ["x", 12, "x", 56, 19, "x", "x", "x", 14, 10, "x"]
*/
let bigNums = [3, 12, 7, 56, 19, 9, 1, 5, 14, 10, 2];
function find_bigNums(nums) {
let results = [];
for(let i=0; i<bigNums.length; i++) {
if(bigNums[i] < 10) {
results.push('x');
}
else {
results.push(nums[i]);
}
} /* end of the for loop */
return results;
} /* end of the function */
find_bigNums(bigNums); /* invoking the function on the data */
// -> ['x', 12, 'x', 56, 19, 'x', 'x', 'x', 14, 10, 'x']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment