Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #25108

Re: Cannot manipulate array produced with string.match

From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: Cannot manipulate array produced with string.match
Date 2014-06-28 01:16 +0000
Organization A noiseless patient Spider
Message-ID <lol51s$or3$2@dont-email.me> (permalink)
References (2 earlier) <lokbfi$vac$1@dont-email.me> <lokfoe$q6k$1@dont-email.me> <lokjjc$o0v$1@dont-email.me> <loknef$inh$1@dont-email.me> <lol4g3$or3$1@dont-email.me>

Show all headers | View raw


On Sat, 28 Jun 2014 01:07:15 +0000, Denis McMahon wrote:

> [code]

Better solution:

var arr = ["fred","jim","pete"," jim","andrew"," jim ","bert",
           "jim ","henry","jim","mike"];
var i = arr.length, j, k;

console.log( arr.toString() );

while ( i-- ) {
    if (arr[i] === 'jim') {
        arr.splice(i, 1);
    }
    else {
        console.log( "'" + arr[i].toString() + "' !== 'jim'" );
        if ( arr[i].toString().length != "jim".length ) {
            console.log( "'" + arr[i].toString() + "'.length [" +
                         arr[i].toString().length +
                         "] != 'jim'.length [" + "jim".length + "]" );
        }
        k = arr[i].toString().length > "jim".length ?
            arr[i].toString().length :
            "jim".length;
        for ( j = 0; j < k; j++ ) {
            if ( arr[i].toString().charAt(j) !== "jim".charAt(j) ) {
                console.log( "arr[i].toString().charAt(" + j + ") [" +
                             arr[i].toString().charAt(j) +
                             "] !== 'jim'.charAt(" + j + ") [" +
                             "jim".charAt(j) + "]" );
            }
            if ( arr[i].toString().charCodeAt(j) !==
                 "jim".charCodeAt(j) ) {
                console.log( "arr[i].toString().charCodeAt(" + j +
                             ") [" + arr[i].toString().charCodeAt(j) +
                             "] !== 'jim'.charCodeAt(" + j + ") [" +
                             "jim".charCodeAt(j) + "]" );
            }
        }
    }
}

console.log( arr.toString() );

-- 
Denis McMahon, denismfmcmahon@gmail.com

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Cannot manipulate array produced with string.match SteveYoungTbird <stephen.young@chello.at> - 2014-06-27 09:17 +0200
  Re: Cannot manipulate array produced with string.match Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-27 10:02 +0000
    Re: Cannot manipulate array produced with string.match SteveYoungTbird <stephen.young@chello.at> - 2014-06-27 20:00 +0200
      Re: Cannot manipulate array produced with string.match Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-27 19:13 +0000
        Re: Cannot manipulate array produced with string.match SteveYoungTbird <stephen.young@chello.at> - 2014-06-27 22:18 +0200
          Re: Cannot manipulate array produced with string.match SteveYoungTbird <stephen.young@chello.at> - 2014-06-27 23:24 +0200
            Re: Cannot manipulate array produced with string.match Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-28 01:07 +0000
              Re: Cannot manipulate array produced with string.match Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-28 01:16 +0000
            Re: Cannot manipulate array produced with string.match Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-28 23:53 +0200
              Re: Cannot manipulate array produced with string.match SteveYoungTbird <stephen.young@chello.at> - 2014-06-29 22:24 +0200
                Re: Cannot manipulate array produced with string.match Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-29 23:19 +0200
  Re: Cannot manipulate array produced with string.match JJ <jj4public@vfemail.net> - 2014-06-27 19:31 +0700

csiph-web