Skip to content

Instantly share code, notes, and snippets.

@javierd79
Last active September 25, 2022 21:21
Show Gist options
  • Save javierd79/a016dc2fc3383cdab007a220cf75ee58 to your computer and use it in GitHub Desktop.
Save javierd79/a016dc2fc3383cdab007a220cf75ee58 to your computer and use it in GitHub Desktop.
The function called fakeBinary receives as argument size(size) which is a number (integer) and must return a string of 1s and 0s with the indicated size.
let result = []
const REGEX_INT = /^-?\d+$/;
const isNumber = (value) => {
return REGEX_INT.test(value);
}
const fakeBinary = (param) => {
if (isNumber(param)){
for (let i = 0; i < param; i++) {
if(i % 2 === 0) {
result.push(1);
} else {
result.push(0);
}
}
console.log(result.map((bin, index) => (bin)).join(''));
} else {
console.log('Is not a Number, please enter a valid Number');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment