Turn on thread page Beta
    • 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));
Submit reply
Turn on thread page Beta
Updated: November 14, 2017

University open days

  1. Loughborough University
    General Open Day Undergraduate
    Fri, 21 Sep '18
  2. University of Cambridge
    Churchill College Undergraduate
    Fri, 21 Sep '18
  3. Richmond, The American International University in London
    Undergraduate Open Day Undergraduate
    Fri, 21 Sep '18
Which accompaniment is best?

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.