Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter

    I have written most of the code, but it keeps returning null instead of finding the 483373 in the students array, can someone help?

    Implement a function find(needle, haystack) that
    -uses an iterative linear sort algorithm
    -returns the object in haystack which has the snr property matching the needle
    -returns null if there is no object in haystack that has a snr property matching the needle

    function find(needle, haystack){

    if(haystack.length > 0){
    if(needle == haystack[0]){
    return 0;
    var idx = find(needle, haystack.slice(1));
    if(idx !== null) {

    idx = idx +1 ;
    return idx;

    return null;



    var students =[{name: 'Mark', snr: 9947832}, {name: 'Dave', snr: 483373}, {name: 'Chris', snr: 6482724}];
    console.log(find(483373, students));
Do you agree with the PM's proposal to cut tuition fees for some courses?

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.