Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * DEFINITION
- * @param [unknown] listA
- * @param [unknown] listB
- */
- function combo(listA, listB) {
- if (!Array.isArray(listA)) throw new Error("listA in NOT an array!");
- if (!Array.isArray(listB)) throw new Error("listB in NOT an array!");
- if (listA.length !== listB.length) throw new Error("listA and listB have different length!");
- const result = []
- listA.forEach((elA, idx) => {
- result.push(elA, listB[idx])
- })
- return result;
- }
- // IMPLEMENTATION with some failure cases and one success
- try {
- var fusion = combo(1, ["A"]);
- console.log(fusion);
- } catch (error) {
- console.warn(error);
- }
- try {
- var fusion = combo([1], "A");
- console.log(fusion);
- } catch (error) {
- console.warn(error);
- }
- try {
- var fusion = combo([1, 2, 3], ["a", "b"]);
- console.log(fusion);
- } catch (error) {
- console.warn(error);
- }
- var letters = ['b','c','d','e','f']
- var numbers = [2,3,4,5,6]
- try {
- var fusion = combo(letters, numbers);
- console.log(fusion);
- } catch (error) {
- console.error(error);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement