Groovy web console

subscribe to the feed Subscribe
to this
site

ProofIT_Dvisible_By_2_And_3

Published 3 weeks ago by Jurgis Sipols
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
/*
    Write the implementation of the method `findFirstNumberThatDividesByTwoAndThree`.
    Method returns null if input format is wrong and or no number is found in the List that is divisable by 2 and 3, or else
    method returns first number that is divisable by 2 and 3.
    There are some test cases at the end of the script to verify the logic. Feel free to add more cases.
*/


def findFirstNumberThatDividesByTwoAndThree(numbers) {
    return null
}

println findFirstNumberThatDividesByTwoAndThree([1, 2, 3, 6])     // expect 6
println findFirstNumberThatDividesByTwoAndThree([6, 12])          // expect 6
println findFirstNumberThatDividesByTwoAndThree([1, 1])           // expect null
println findFirstNumberThatDividesByTwoAndThree([1, 2, 3, null])  // expect null
println findFirstNumberThatDividesByTwoAndThree([])               // expect null
println findFirstNumberThatDividesByTwoAndThree(null)             // expect null